Skip to main content

Center an element with CSS Grid

It’s not uncommon to go a week without a developer complaining on Twitter about how hard it is to center an element using CSS.

Here it is, two lines of CSS to center an element within its parent.

.parent {
display: grid;
place-items: center;
}

It’s beautiful.