The align-content property is a powerful CSS tool that controls how multiple lines of content are distributed along the cross-axis in flexbox and grid layouts. Unlike align-items which aligns individual items, align-content works specifically with wrapped content and multiple rows or columns.
Understanding CSS Align-Content
The align-content property only takes effect when there are multiple lines of flex items or grid tracks. It distributes space between and around these lines along the cross-axis (perpendicular to the main axis).
Key Points:
- Works only with multi-line layouts (flex-wrap: wrap or grid)
- Controls cross-axis alignment of entire lines, not individual items
- Has no effect on single-line flex containers
- Applies to both flexbox and CSS Grid
CSS Align-Content Values
The align-content property accepts several values that determine how lines are distributed:
Basic Values
1. flex-start (start)
Lines are packed toward the start of the cross-axis.
.container {
display: flex;
flex-wrap: wrap;
align-content: flex-start;
height: 200px;
}
2. center
Lines are centered along the cross-axis.
.container {
display: flex;
flex-wrap: wrap;
align-content: center;
height: 200px;
}
3. flex-end (end)
Lines are packed toward the end of the cross-axis.
.container {
display: flex;
flex-wrap: wrap;
align-content: flex-end;
height: 200px;
}
Space Distribution Values
4. space-between
Lines are evenly distributed with the first line at the start and last line at the end.
.container {
display: flex;
flex-wrap: wrap;
align-content: space-between;
height: 200px;
}
5. space-around
Lines are evenly distributed with equal space around each line.
.container {
display: flex;
flex-wrap: wrap;
align-content: space-around;
height: 200px;
}
6. space-evenly
Lines are evenly distributed with equal space between and around them.
.container {
display: flex;
flex-wrap: wrap;
align-content: space-evenly;
height: 200px;
}
7. stretch (default)
Lines stretch to fill the remaining space in the container.
.container {
display: flex;
flex-wrap: wrap;
align-content: stretch; /* default value */
height: 200px;
}
Interactive Demo
Try different align-content values with this interactive demo:
Current value: stretch
Effect: Lines stretch to fill the remaining space in the container.
CSS Grid and Align-Content
The align-content property also works with CSS Grid, controlling how grid tracks are aligned within the grid container:
Grid Example
.grid-container {
display: grid;
grid-template-columns: repeat(3, 80px);
grid-auto-rows: 60px;
align-content: center;
height: 200px;
gap: 10px;
}
Common Use Cases
1. Card Layouts
Perfect for creating responsive card grids where cards wrap to new lines:
Card 1
Sample card content with some text.
Card 2
Another card with different content length.
Card 3
Third card in the layout.
.card-container {
display: flex;
flex-wrap: wrap;
align-content: flex-start;
gap: 15px;
}
.card {
width: 150px;
padding: 15px;
border: 1px solid #dee2e6;
border-radius: 8px;
}
2. Image Gallery
Center multiple rows of images within a container:
.gallery {
display: flex;
flex-wrap: wrap;
align-content: center;
justify-content: center;
height: 280px;
gap: 10px;
}
Browser Support
The align-content property has excellent browser support:
| Browser | Support | Notes |
|---|---|---|
| Chrome | 21+ | Full support |
| Firefox | 28+ | Full support |
| Safari | 9+ | Full support |
| Edge | 12+ | Full support |
| Internet Explorer | 11 | Partial support |
Common Mistakes and Solutions
<div style=”background: #fff3cd; border: 1px solid #ffe








