π What is justify-self?
justify-self is a CSS Grid item-level property that controls thehorizontal alignment of a specific grid item inside its own grid cell. It overrides the container-level justify-items property, giving you precise control over individual elements.
π Where does justify-self apply?
β Works only on **grid items** (children of a grid container)
β Applies to **horizontal alignment** inside the grid cell
β Overrides justify-items when needed
π― Available Values
| Value | Meaning |
|---|---|
| start | Aligns the item to the left of its cell |
| center | Centers the item horizontally |
| end | Aligns the item to the right of its cell |
| stretch | Stretches item to fill full cell width (default) |
π§ͺ Basic Example
Center a Single Item
.container {
display: grid;
grid-template-columns: repeat(3, 150px);
justify-items: start; /* default for all */
}
.item2 {
justify-self: center; /* override for this item */
}Only .item2 will be centered, the rest align to the left.
π Visual Guide

π§± Using All Values
justify-self Variants
.item1 { justify-self: start; }
.item2 { justify-self: center; }
.item3 { justify-self: end; }
.item4 { justify-self: stretch; }π§ justify-self vs justify-items
| Property | What It Controls |
|---|---|
| justify-items | Horizontal alignment of all items in the grid |
| justify-self | Horizontal alignment of one item |
Note
π§© Practical Use Cases
- Centering an icon inside a button in a grid layout
- Aligning specific cards differently in a card grid
- Right-aligning a single badge inside its grid cell
- Overriding global justify-items rules
π§ͺ Example: Tooltip or Badge Alignment
Right-Aligned Badge
.product {
display: grid;
grid-template-columns: 1fr auto;
}
.badge {
justify-self: end;
}The badge will stick to the right side of its cell.
π± Responsive Example
Responsive justify-self
.cta {
justify-self: center;
}
@media (min-width: 768px) {
.cta {
justify-self: end;
}
}Small screens β centered CTA
Large screens β right-aligned CTA
β οΈ Common Mistakes
- Using justify-self on non-grid items (wonβt work)
- Expecting justify-self to align content vertically (use align-self instead)
- Not realizing stretch is the default value
Note
β’ justify-self = horizontal (leftβright)
β’ align-self = vertical (topβbottom)
π₯ Summary
justify-self gives you fine-grained control over the horizontal alignment of individual grid items. It is perfect for exceptions when you want one item to align differently from the others.
Learn more here βMDN Docs π