Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Flexbox

The place-items property

Reference for the CSS place-items shorthand: set align-items and justify-items together, center content in grid cells, and avoid the flexbox pitfall.

The place-items property is a shorthand for align-items and justify-items. It sets the default alignment of every child inside its own grid area, on both axes at once. You can still override it per item with place-self.

If you give one value it is used for both axes. With two values the first is align-items (block axis) and the second is justify-items (inline axis).

CSS
.card { display: grid; place-items: center; }

Try it

Centered content in a grid

Each coloured cell is itself a one-item grid, so its place-items value positions the white label inside it: centered, at the top right (start end), and at the bottom left (end start). The next example shows the more common use, on the outer grid.

place-items on the grid container

Each item shrinks to its content and sits in the middle of its cell. Without place-items the items would stretch to fill their cells.

Syntax

CSS
place-items: <'align-items'> <'justify-items'>?
  • Initial value: normal
  • Applies to: all elements (the longhands decide what actually happens)
  • Inherited: no
  • Animatable: no
  • Computed value: as specified for the longhands

Values

Value Description
normal Default. In grid, items stretch to fill the cell.
stretch Items grow to fill the cell in that axis unless a size is set.
start, end Aligns to the start or end edge of the cell.
center Centers the item in the cell.
self-start, self-end Aligns by the item's own writing mode.
baseline Aligns first baselines (useful for text in different font sizes).
safe / unsafe Optional overflow keyword before a position.

Usage notes

  • Flexbox gotcha. In a flex container justify-items is ignored, so place-items: center only centers on the cross axis. Use justify-content for the main axis, or switch to grid, where display: grid; place-items: center really centers.
  • Items shrink-wrap. Anything other than stretch makes items only as large as their content. Set a width or height if you want a specific size.
  • Cell, not container. The alignment is relative to each grid area; to move the whole grid inside its container use place-content.
  • Exceptions. Override single items with align-self, justify-self or place-self.

Browser support

Supported in all current browsers.