CSS Reference ยท Flexbox
The align-content property
Reference for the CSS align-content property: how it distributes wrapped flex lines and grid tracks on the cross axis, with values and live examples.
The align-content property distributes the free space on the cross axis between the lines of a multi-line flex container, or between the rows of a grid. While align-items places each item inside its own line, align-content places the lines as a group inside the container.
It only matters when the container has more cross-axis space than its lines need, and, for flexbox, only when the container wraps (flex-wrap: wrap or wrap-reverse).
.gallery { display: flex; flex-wrap: wrap; height: 400px; align-content: flex-start; }
Try it
Syntax
align-content: normal | <baseline-position> | <content-distribution> | <overflow-position>? <content-position>; /* <content-distribution>: space-between | space-around | space-evenly | stretch */ /* <content-position>: center | start | end | flex-start | flex-end */
- Initial value:
normal(behaves likestretch) - Applies to: multi-line flex containers and grid containers; current browsers also apply it to block containers
- Inherited: no
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
normal / stretch |
Lines grow equally to fill the container (if their items can stretch). |
flex-start / start |
Lines are packed at the cross-start edge. |
flex-end / end |
Lines are packed at the cross-end edge. |
center |
Lines are packed in the middle. |
space-between |
First and last lines touch the edges; space is shared between lines. |
space-around |
Equal space around every line (half at the edges). |
space-evenly |
The same space between lines and at both edges. |
baseline |
Aligns the container's first baseline (grid and block use). |
safe / unsafe |
Optional prefix controlling overflow, as for the other alignment properties. |
Usage notes
- Needs spare space. If the container's height is set by its content, the lines fill it exactly and there is nothing to align. Give the container a height (or
min-height) to see an effect. - Needs wrapping. A flex container with
flex-wrap: nowrapis a single-line container and ignoresalign-content. Usealign-itemsthere. Withwrap, even a container whose items all fit on one line is treated as multi-line. stretchis the default. That is why wrapped lines in a tall container spread out evenly and items in them grow taller.- Mind the axis. In
flex-direction: columnwith wrapping, the cross axis is horizontal, soalign-contentplaces columns left to right. - Gaps stay in place.
gapbetween lines is respected before extra space is distributed. - In grid. It aligns the whole set of row tracks when the grid is taller than its tracks. Its horizontal twin is
justify-content.
Browser support
Supported in every browser for flexbox and grid. Use on plain block containers is in current browsers only.