π What is justify-items?
justify-items is a CSS Grid property that controls thehorizontal alignment of grid items *within their grid cells*. It applies to **all grid items at once**, unless overridden by justify-self on an individual item.
π Where does justify-items apply?
It applies **only to grid containers** (i.e., elements with display: grid or inline-grid). It affects horizontal alignment **inside each cell**, not the entire grid.
π― Available Values
| Value | Description |
|---|---|
| start | Aligns items to the left of their grid cell |
| center | Centers items horizontally |
| end | Aligns items to the right |
| stretch | Stretches items to fill the full cell width (default) |
π§ͺ Basic Example
justify-items: center
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: center;
}All grid items inside each cell will be centered horizontally.
π Visual Example

π§± Example With All Values
justify-items Variations
.start { justify-items: start; }
.center { justify-items: center; }
.end { justify-items: end; }
.stretch { justify-items: stretch; }π§ justify-items vs justify-content
| Property | Aligns What? |
|---|---|
| justify-items | Items *inside each* grid cell (horizontal) |
| justify-content | The **entire grid** inside the container (horizontal) |
Note
justify-items = item alignment
justify-content = grid alignment
π¦ Override With justify-self
If you want to align just one grid item, use justify-self.
Overriding justify-items
.container {
display: grid;
justify-items: center; /* default for all items */
}
.item1 {
justify-self: end; /* override just this item */
}π§© Real-World Use Cases
- Centering icons inside grid-based buttons
- Aligning text inside grid cells
- Horizontal alignment consistency in dashboards
- Perfectly centering cards or images
π± Responsive Notes
justify-items works consistently across all breakpoints. You can override it using media queries if needed.
Responsive justify-items
.container {
justify-items: start;
}
@media (min-width: 768px) {
.container {
justify-items: center;
}
}β οΈ Common Mistakes
- Using justify-items thinking it aligns the entire grid (thatβs justify-content)
- Expecting it to vertically align items (use align-items instead)
- Applying justify-items on grid items instead of the container
Note
π₯ Summary
justify-items controls how grid items are horizontally positioned inside their grid cells. Whether it's left, center, right, or stretched, this property gives you fine control over internal alignment, ensuring clean and consistent UI layouts.
Learn more βMDN Docs π