Vertically Center Text in a DIV Element

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..


css code:

<div class="div-eg">Some Text</div>

html code:

.div-eg {
  height: 200px;
  text-align: center;
  background: #eee;
  border:1px solid #222
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:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap