Flexbox vertical and horizontal centering

October 11, 2013

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.

Join the mailing list!

Subscribe to get notified about future articles and stay in touch via email.

I write about Django, Kubernetes, Docker, automation- and deployment topics, but would also like to keep you up to date about news around the business-side of things.

Privacy and your data: You can get more information about the usage of your data, the storage of your registration, sending out mails with the US-provider ConvertKit, statistical analysis of emails sent and your possibility to unsubscribe in my Privacy Policy.

I use the US-provider ConvertKit for email automation. By clicking to submit this form, you acknowledge that the information you provide will be transferred to ConvertKit for processing in accordance with their Privacy Policy and Terms.

We won't send you spam. Unsubscribe at any time. Powered by ConvertKit