Search code examples
htmlcsstextcenter

How to center text vertically in HTML using CSS only


I have a very simple HTML. Due to some limitations, I cannot modify the HTML content. I want to center the text vertically only using CSS.

<html>
    <head>...</head>

    <body>
        <div>Oops, the webpage is currently not available.</div>
    </body>
</html>

Note that the size of the HTML can be variable.

In addition, if the text cannot be displayed in one line, it should be broken into multiple lines.

Is it possible?


Solution

  • I think vertical-align only works for content which is in a table. For your simple page you could put the content in a table instead of a div to avoid this problem.

    There are some workarounds, see http://phrogz.net/css/vertical-align/index.html