How to do vertical centering in CSS

It feels like it should be a simple task but it's easy to tie yourself in knots if you don't know any good tricks for vertical centering. Jake Archibald has two neat ways for vertically centering things in CSS.

Here's his method (opens in new tab) for modern browsers, as hosted on the collaborative code pastebin JsBin (opens in new tab):

Vertical centering in modern browsers, by Jake Archibald

Click on the image to see a larger version
(opens in new tab)

And here's one (opens in new tab) that works for browsers going back to IE8:

Archibald's method for centering in old browsers

Click on the image to see a larger version
(opens in new tab)

You can follow some further discussion about these and other methods on Twitter, here (opens in new tab).

Liked this? Read these!

Thank you for reading 5 articles this month* Join now for unlimited access

Enjoy your first month for just £1 / $1 / €1

*Read 5 free articles per month without a subscription

Join now for unlimited access

Try first month for just £1 / $1 / €1

The Creative Bloq team is made up of a group of design fans, and has changed and evolved since Creative Bloq began back in 2012. The current website team consists of six full-time members of staff: Editor Kerrie Hughes, Deputy Editor Rosie Hilder, Deals Editor Beren Neale, Senior News Editor Daniel Piper, Digital Arts and Design Editor Ian Dean, and Staff Writer Amelia Bamsey, as well as a roster of freelancers from around the world. The 3D World and ImagineFX magazine teams also pitch in, ensuring that content from 3D World and ImagineFX is represented on Creative Bloq.