Centered
justify-content and align-items center the child.
If you searched how to center a div in CSS, the right technique depends on context: flexbox and grid for layout regions, margin auto for block elements, and transform for overlay modals. Compare each approach live below.
The most common pattern for cards, heroes, and empty states.
justify-content and align-items center the child.
.parent {
display: flex;
justify-content: center;
align-items: center;
min-height: 12rem;
}One property on the grid container centers all children.
place-items: center is shorthand for align and justify.
.parent {
display: grid;
place-items: center;
min-height: 12rem;
}Works on block-level elements with a set width.
The block needs width less than 100%.
.card {
width: min(20rem, 100%);
margin-inline: auto;
}