CSS propertyGrid
justify-items
Aligns all items within their cells along the horizontal axis.
- Initial value
legacy- Inherited
- No
- Animatable
- no
- Applies to
- all elements, the effect shows up in grid containers
- JavaScript
element.style.justifyItems = "center"
Example
#CSS
.icons {
display: grid;
grid-template-columns: repeat(4, 1fr);
justify-items: center;
}Example HTML
<div class="icons stage">
<span class="box">π </span><span class="box">π</span><span class="box">π</span><span class="box">βοΈ</span>
</div>Preview
Definition and usage
#The justify-items property is set on a grid container. It decides how each item sits inside its cell horizontally: stretching across the full width of the cell, hugging the left or right side, or sitting in the center.
By default, grid items stretch. Switching to start or center makes an item only as wide as its content, leaving the rest of the cell empty.
This property doesnβt work in Flexbox, because there, items are positioned on the main axis with justify-content and margins.
Syntax
#Syntax
justify-items: normal | stretch | start | end | center | legacy;Values
#Values in practice
#stretch
Items fill the full width of their cells.
.demo { justify-items: stretch; }start
Items hug the left edge of their cells.
.demo { justify-items: start; }center
Items sit in the center of their cells.
.demo { justify-items: center; }end
Items hug the right edge of their cells.
.demo { justify-items: end; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- To align one item differently from the rest, use
justify-selfon that item. - The
place-itemsshorthand setsalign-itemsandjustify-itemsat once.
Related entries
#- justify-selfAligns a single item within its grid cell along the horizontal axis.
- place-itemsA shorthand that sets align-items and justify-items at the same time.
- align-itemsAligns items along the cross axis of a flex or grid container.
- justify-contentPositions items along the main axis of a flex or grid container.
Spotted a mistake or missing an example? Write to us.