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

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

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!