Flexbox vertical and horizontal centering

October 11, 2013 [ html | css ]

Assuming you want to center a single element on a page vertically and horizontally, in Chromium it can be achieved the following way:

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8" />
      html {
        height: 100%;

      body {
        height: 100%;

        display: flex;
        justify-content: center;
        align-items: center;

    <h1>I am centered!</h1>

Specifying the height attribute for html as well as body is key.

Want to be notified when I publish new content?

Just enter your name and email below. You will also get content that I share exclusively with the list, and zero spam!