Explore Courses Blog Tutorials Interview Questions
0 votes
in Web Technology by (20.3k points)

I have a div set to display: block (90px height and width), and I have some text inside.

I need the text to be aligned in the center both vertically and horizontally.

I have tried text-align: center, but it doesn't do the horizontal part, so I tried vertical-align: middle, but it didn't work.

Any ideas?

1 Answer

0 votes
by (40.7k points)

Try this :

text-align: center;

vertical-align: middle;

line-height: 90px;       /* The same as your div height */

The below code will support multiple lines of text:

position: relative;

top: 50%;

transform: translateY(-50%);


To shrink-wrap the width use the code given below:

float: left;

top: 50%;

left: 50%;

transform: translate(-50%, -50%);


Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers


108k users

Browse Categories