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: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

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