Languages

CSS - vertically center text

0 points
Asked by:
DrJoystick
585

How can I vertically center text inside my element?

I've tried vertical-align: middle but it doesn't work.

My code:

1 answer
0 points
Answered by:
Admin Dirask Community
4380

The easiest solution would be to use flexbox (display: flex) like this:

As an alternative you can also use line-height property:

Note:

Centering text inside element is a similar problem to centering element vertically. For more solutions go to this article: CSS - center element vertically.

 

Practical examples

1. Using flexbox

2. Using line-height property

 

See also

  1. CSS - center element vertically

References

  1. flex - CSS: Cascading Style Sheets | MDN
  2. line-height - CSS: Cascading Style Sheets | MDN
0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join