π What is align-items?
align-items is a CSS Grid (and Flexbox) property that controls thevertical alignment of grid items *within their grid cells*. It sets the default vertical alignment for **all items** unless overridden byalign-self on individual items.
π Where does align-items apply?
It applies to the **grid container**, not to grid items directly. Only works when the container has display: grid or inline-grid.
π― Available Values
| Value | Description |
|---|---|
| start | Aligns items to the top of their cell |
| center | Centers items vertically |
| end | Aligns items to the bottom |
| stretch | Stretches items to fill cell height (default) |
π§ͺ Basic Example
align-items: center
.container {
display: grid;
grid-template-rows: repeat(3, 100px);
align-items: center;
}All grid items will be vertically centered inside their cells.
π Visual Alignment Example

π§± Example Using All Values
align-items: start | center | end | stretch
.start { align-items: start; }
.center { align-items: center; }
.end { align-items: end; }
.stretch { align-items: stretch; }π§ align-items vs align-content
| Property | Aligns What? |
|---|---|
| align-items | Items *inside each* grid cell (vertical) |
| align-content | The **entire grid** inside the container (vertical) |
Note
align-items = item alignment
align-content = grid alignment
π¦ Override align-items Using align-self
If you want individual item-level control, use align-self.
Override Example
.container {
display: grid;
align-items: center; /* default for all items */
}
.item1 {
align-self: start;
}
.item2 {
align-self: end;
}π§© Real-World Use Cases
- Vertically centering icons inside buttons or cards
- Aligning form labels or inputs consistently
- Creating visually balanced dashboard widgets
- Ensuring card content stays aligned regardless of text length
π± Responsive Behavior
align-items adapts naturally across breakpoints. For custom behavior, override it in media queries:
Responsive align-items
.container {
align-items: stretch;
}
@media (min-width: 768px) {
.container {
align-items: center;
}
}β οΈ Common Mistakes
- Using align-items to try aligning the whole grid (use align-content instead)
- Expecting vertical alignment when row height is fixed and equal to item height
- Setting align-items on grid items instead of the container
Note
π₯ Summary
align-items sets the vertical alignment of all grid items inside their respective cells. By mastering this property, you gain complete control over internal item positioning β making UI grids clean, balanced, and visually polished.
Learn more atMDN Docs π