Easy horizontal and vertical centering in CSS

Categories

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.

Hello, I’m Andy and I’ll help you build fast & visually stunning websites.

I am currently setting up a new creative agency called Set Creative Studio and we are taking on projects for 2022, so if you have a project in mind, get in touch.