how to vertically middle align text in div-HTML tip

  • Home
  • Blog
  • how to vertically middle align text in div-HTML tip

Recently in one of the project I have to vertical align text in div. so doing some internet search I have found there are no proper way to do it. So I thought it would be good do share this within my readers. Here is the code do vertically align text in div.

this is a very long text this is a very long text this is a very long text this is a very long text this is a very long text this is a very long text 

Here in above code you can see that I have created two divs first one will serve container for other div and other div has the text which I want to align vertically in div. So in container div you can see I have given its style to display table and in child div which has the text I have given its display style to table-cell and given vertical-align property to middle. That’s it now when you run this in browser you can see text is vertically aligned.

Hope you liked it..Stay tuned for more..Till then happy programming.