CSS place-items

The place-items property is a shorthand that sets align-items and justify-items at once. It is the shortest way to center content in a grid. Pick a value below to see it live, or type your own.

LIVEPreview
A
B
C
D

Syntax

place-items: <align-items> <justify-items>;

place-items: center;        /* both directions */
place-items: start end;     /* top, right */

With one value, both directions use it. With two, the first is the vertical (block) alignment and the second the horizontal (inline) alignment.

Center anything in two lines

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

This centers a child horizontally and vertically, no matter its size. It is the shortest centering technique in CSS.

Values explained

ValueWhat it does in each grid cell
stretchItems fill their cell (default for items without a fixed size)
centerItems are centered in their cell
startItems sit at the top-left of their cell (in left-to-right languages)
endItems sit at the bottom-right of their cell

place-items in flexbox

In a flex container only the align-items part has an effect, because flexbox has no justify-items. For flex layouts, use align-items with justify-content instead. Related shorthands follow the same pattern: place-content aligns the whole grid inside its container, and place-self aligns one item.

Related tools

Frequently Asked Questions

What is the difference between place-items and place-content?

place-items aligns each item inside its own grid cell; place-content aligns the whole grid inside its container when the grid is smaller than the container.

Does place-items work with flexbox?

Only the vertical part (align-items) works in flexbox. Use align-items and justify-content for flex layouts.

Why is place-items: center not centering my element?

The parent needs display: grid and enough size; a parent that only wraps its content has no extra space to center in.

More CSS properties

Tool last updated: