Skip to content
Tutorials Center
My learning

Topics

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).

CSS
.gallery { display: flex; flex-wrap: wrap; height: 400px; align-content: flex-start; }

Try it

Aligning the lines
No effect without wrapping

Syntax

CSS
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 like stretch)
  • 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: nowrap is a single-line container and ignores align-content. Use align-items there. With wrap, even a container whose items all fit on one line is treated as multi-line.
  • stretch is 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: column with wrapping, the cross axis is horizontal, so align-content places columns left to right.
  • Gaps stay in place. gap between 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.