← All snippets

Center a Div (Flexbox)

The classic "how do I center a div" — solved in 3 lines with flexbox. Works horizontally and vertically.

patterns

Code

.parent {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}