CSS Layout How to - Vertical Middle Align text








Question

We would like to know how to vertical Middle Align text.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
body {<!--from w  w w.j  a v  a2  s .  c  om-->
  width: 100%;
  height: 100%;
}

div {
  position: absolute;
  height: 100%;
  width: 100%;
  display: table;
}

h1 {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
}
</style>

</head>
<body>
  <div>
    <h1>Text</h1>
  </div>
</body>
</html>

The code above is rendered as follows: