Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Flexbox

The justify-self property

Reference for the CSS justify-self property: align one grid item along the inline axis of its area with start, end, center, stretch and more, with live examples.

The justify-self property aligns a single box along the inline axis of the area it lives in. In a grid, that area is the item's grid cell (or the cells it spans), and the inline axis is the horizontal one in left-to-right languages like English.

It overrides the container's justify-items for just this one item. Use it in grid layouts. In flexbox it has no effect: flex items are positioned on the main axis with justify-content and auto margins instead.

CSS
.badge { justify-self: end; }

Try it

Justify individual grid items

The first three items shrink to their content and sit at the start, middle and end of their columns. The last item stretches across the whole row.

Syntax

CSS
justify-self: auto | normal | stretch | <baseline-position> | <self-position>
            | [ safe | unsafe ]? <self-position> | left | right;
  • Initial value: auto
  • Applies to: grid items (and, per the specification, block-level and absolutely positioned boxes, but grid is where it is reliably useful)
  • Inherited: no
  • Animatable: no (discrete)
  • Computed value: as specified

Values

Value Description
auto Uses the container's justify-items value. This is the default.
normal Behaves like stretch for grid items without a fixed width, otherwise like start.
stretch Grows the item to fill the area, unless a width is set.
start, end Pins the item to the start or end edge of the area in the writing direction.
center Centers the item in the area.
self-start, self-end Aligns by the item's own writing direction instead of the container's.
flex-start, flex-end Treated like start and end outside flex layout.
left, right Physical edges, regardless of writing direction.
baseline Aligns the item's first baseline with the other baseline-aligned items.
safe / unsafe Optional keyword before a position. safe avoids overflowing the start edge; unsafe allows it.

Usage notes

  • Shrink-wrapping. Any value other than stretch (or normal on an auto-width item) makes the item only as wide as its content. Add a width if you need something else.
  • Not for flexbox. Use margin-left: auto or justify-content on a flex container to move flex items sideways.
  • Whole container at once. Set justify-items on the grid container, then use justify-self for the exceptions.
  • Both axes. place-self sets this and align-self in one declaration.
  • Logical keywords. Prefer start and end over left and right so layouts adapt to right-to-left languages.

Browser support

Works for grid items in all current browsers.