Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Flexbox

The justify-items property

Reference for the CSS justify-items property: the default inline-axis alignment of grid items, its values, why flexbox ignores it, and live examples.

The justify-items property sets the default inline-axis alignment of all items inside their grid areas: left to right in horizontal, left-to-right text. It is the container-level version of justify-self, which overrides it for a single item.

It is a grid property. Flex containers ignore it, because flexbox has no per-item justification: on the main axis use justify-content, and on the cross axis align-items.

CSS
.grid { display: grid; grid-template-columns: repeat(3, 1fr); justify-items: center; }

Try it

Items inside their cells
Ignored by flexbox

Syntax

CSS
justify-items: normal | stretch | <baseline-position> | <overflow-position>? [ <self-position> | left | right ]
  | legacy | legacy && [ left | right | center ];

/* <self-position>: center | start | end | self-start | self-end | flex-start | flex-end */
  • Initial value: legacy
  • Applies to: grid containers; current browsers also apply it to block containers
  • Inherited: no
  • Animatable: no
  • Computed value: as specified

Values

Value Description
legacy / normal Default. Items with an auto width stretch to fill the cell; items with a set width sit at the start.
stretch Items with an auto width fill the cell.
start, end Items sit at the start or end of the cell (writing-mode aware).
self-start, self-end Based on the item's own writing mode.
center Items are centered in the cell.
left, right Items sit at the physical left or right of the cell.
baseline Aligns the items' first baselines along the inline axis (first/last forms exist).
safe / unsafe Optional prefix controlling overflow behaviour.

Usage notes

  • The cell is the reference. justify-items aligns an item inside its grid area, not inside the whole container. To place the tracks themselves inside the container use justify-content.
  • Stretching needs auto. An item with a set width does not stretch, and justify-items: stretch only grows items whose width is auto.
  • Shrink-wrap side effect. Any value other than stretch makes items take the width of their content, so image or text blocks may become narrower than the cell.
  • Per-item override. Use justify-self on one item to break the rule.
  • Vertical twin. align-items does the same on the block axis. place-items sets both in one declaration.
  • Not for flexbox. Flexbox ignores it. If you set it in a flex container, nothing happens; auto margins are the main-axis tool for single items.

Browser support

Supported in every current browser for grid. Using it on block containers is available only in newer versions.