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.
.badge { justify-self: end; }
Try it
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
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(ornormalon an auto-width item) makes the item only as wide as its content. Add awidthif you need something else. - Not for flexbox. Use
margin-left: autoorjustify-contenton a flex container to move flex items sideways. - Whole container at once. Set
justify-itemson the grid container, then usejustify-selffor the exceptions. - Both axes.
place-selfsets this andalign-selfin one declaration. - Logical keywords. Prefer
startandendoverleftandrightso layouts adapt to right-to-left languages.
Browser support
Works for grid items in all current browsers.
Related
justify-itemsโ default for every item in the containeralign-selfโ the block-axis counterpartplace-selfโ shorthand for both- Lesson: Grid Alignment