Front-end education for the real world. Since 2018.





Easy horizontal and vertical centering in CSS

Andy Bell

Topic: CSS

Centering elements with CSS is completely trivial these days and this little snippet will do exactly that for you, using CSS Grid.

Code language
css

body {
  display: grid;
  place-items: center;
}

If you apply it to the body, make sure you add min-height: 100vh too, but also, be wary of issues that can cause with iOS.

Enjoyed this article? You can support us by leaving a tip via Open Collective


Newsletter