If you want to center a text within a <div> element using CSS, then you can make use of the text-align attributes value set as center..
Example:
css code:
<div class="div-eg">Some Text</div>
html code:
.div-eg {
width:400px;
height: 200px;
text-align: center;
background: #eee;
border:1px solid #222
}
Output:
Some Text
Facing issues? Have Questions? Post them here! I am happy to answer!
Author Info:
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
More Posts related to CSS,
- How to create a circular Image using pure CSS Code
- Horizontally Center Align tag in HTML using CSS
- Add scroll to div element in HTML Css
- Change CSS Background Opacity with Examples
- How to make text bold using CSS
- How to place two div elements next to each other
- Vertically Center Text in a DIV Element
- align image at middle of div element
- Tailwind CSS Hello World Example
- How to make div or text in html unselectable using CSS
- Only Chessboard using HTML and CSS Code Example
- Simple CSS Grid Example
- How to set CSS background-Image Property
- CSS Background Opacity with Examples
- reCAPTCHA Implementation Tutorial
- List of 32 CSS cursors web developers must know about
- How to Vertically Center Align Text in a Div using CSS Code Example
- 10 Must Know CSS Border Styles with Examples
- Tutorial : Simple Lightweight Pure CSS based Vertical Navigation Menu
- CSS: Apply opacity only for div background and not text
- Set Falling Show on Website for Christmas using Pure CSS Code
- How to make jsfiddle bootstrap ready
- Elegant CSS Box Shadows Ideas
- Responsive Web Design with CSS Media Queries: A Beginner's Tutorial [Updated for 2023]
- How to Center Align Image in Bootstrap
More Posts:- How to Restart or Reload Nginx Server Service on Linux - Linux
- What does has notifications silenced in Messages App mean in iPhone - iOS
- New Mac? How to install Native Chrome on M1/M2 Mac - Chrome
- Java monitoring and management console [jconsole] - Java
- How to Decode Base64 Data String in Python - Python
- Java: Collect Stream as ArrayList or LinkedList - Java
- How to install Java 11 on Mac - Java
- IntelliJ Keyboard Shortcut to remove unused imports [Java] - Java