align-content is easily confused with align-items, but it operates on an entirely different level: align-items aligns individual items within their own line along the cross axis, while align-content instead distributes space between multiple wrapped lines as a group, relative to the container's overall cross-axis size — this means align-content has no visible effect at all on a flex container with flex-wrap: nowrap, or one whose items all happen to fit on a single line even with wrapping enabled, since there's only one line and therefore no inter-line space to distribute in the first place.
1Understanding Align-content
align-content is easily confused with align-items, but it operates on an entirely different level: align-items aligns individual items within their own line along the cross axis, while align-content instead distributes space between multiple wrapped lines as a group, relative to the container's overall cross-axis size — this means align-content has no visible effect at all on a flex container with flex-wrap: nowrap, or one whose items all happen to fit on a single line even with wrapping enabled, since there's only one line and therefore no inter-line space to distribute in the first place.
align-content only has a visible effect when a flex container's items have actually wrapped onto multiple lines via flex-wrap: wrap — on a single-line flex container, whether by nowrap or simply because everything fits on one line anyway, align-content has nothing to do and produces no visible effect.
.gallery {
display: flex;
flex-wrap: wrap;
align-content: space-between;
height: 400px;
}2Practical Example
Here is a real-world application of Align-content showing how it is used in production CSS code.
.single-line {
display: flex;
flex-wrap: wrap;
align-content: center;
height: 300px;
}
/* items collectively fit on one line */3Best Practices
Follow these guidelines when working with Align-content:
1. Use align-content specifically when a wrapped, multi-line flex container needs its lines distributed with extra space, like space-between, rather than confusing it with align-items, which affects items within a single line
2. Verify flex-wrap is actually producing multiple lines before troubleshooting why align-content doesn't seem to be having any effect
3. Consider CSS Grid instead of a wrapped flex container for genuinely two-dimensional layouts needing both row and column alignment control simultaneously, which align-content alone doesn't fully provide
Tip: align-content only has a visible effect when a flex container's items have actually wrapped onto multiple lines via flex-wrap: wrap — on a single-line flex container, whether by nowrap or simply because everything fits on one line anyway, align-content has nothing to do and produces no visible effect.
.gallery {
display: flex;
flex-wrap: wrap;
align-content: space-between;
height: 400px;
}