CSS align-content Property

Beginner
7 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The align-content property packs or spreads the lines of a flex or grid container when there is spare space on the cross axis. In a row flex, that axis is vertical: it decides where the wrapped rows sit inside a tall box.

There must be more than one line, and leftover space, or every keyword looks the same. A flex container also needs flex-wrap: wrap. A single line does nothing. To move items inside one line, use align-items.

Standard-track.

Not deprecated and not experimental. Flex and grid values are widely supported. Block layout, multi-column layout, and last baseline are newer and still missing in some browsers.

CSS Syntax

syntax.css
align-content: normal | stretch | center | flex-start | flex-end | space-between | space-around | space-evenly | initial | inherit;

Property Values

ValueDescriptionTry it
normalDefault. In flex and grid this behaves like stretchTry it
stretchLines whose cross size is auto grow to use the spare spaceTry it
centerPacks the lines together in the middle of the containerTry it
flex-startPacks the lines at the start of the cross axisTry it
flex-endPacks the lines at the end of the cross axisTry it
space-betweenFirst line at the start, last line at the end, equal gaps betweenTry it
space-aroundEqual gaps between lines, with half a gap at each edgeTry it
space-evenlyEqual gaps between lines, including the edgesTry it
initialSets this property to its default value, normalTry it
inheritInherits this property from the parent elementTry it

How to Use align-content

Give the container spare space, make more than one line, then pick how those lines share the space.

  1. Set display: flex or display: grid on the container.
  2. Give it a cross size larger than the lines. For a row flex, that is usually height.
  3. On a flex container, set flex-wrap: wrap so items form extra lines. A single line ignores align-content.
  4. Set align-content on the container. It is not inherited.
PieceRequired?Role
Flex or grid containerYesThe box whose lines you are packing
Extra cross-axis spaceYesWithout leftover space, every keyword looks the same
flex-wrap: wrapFlex onlyCreates the extra lines. Grid does not need it
KeywordYescenter, space-between, stretch, and the others below

Live Preview

Four items wrap into two lines inside a tall flex box. Change align-content and watch the lines move.

Two wrapped lines. The spare height is what align-content uses.

Lines
One
Two
Three
Four

align-content: center

CSS Examples

Each snippet adds only what align-content needs: a container, spare space, and more than one line. Use Try It Yourself for a live editor.

Example 1 — Center Wrapped Lines

Pack the two flex lines together in the vertical middle of the box.

CSS
<style>
  section {
    display: flex;
    flex-wrap: wrap;
    height: 180px;
    align-content: center;
    border: 1px solid #ccc;
  }
  div {
    width: 50%;
  }
</style>

<section>
  <div>One</div>
  <div>Two</div>
  <div>Three</div>
  <div>Four</div>
</section>
Try It Yourself

How It Works

  1. Make a row flex. display: flex lays children out in a row.
  2. Force a second line. width: 50% fits two items per row, so Three and Four wrap. flex-wrap: wrap allows that wrap.
  3. Leave spare height. height: 180px is taller than the two lines. The border shows that empty space.
  4. Center the lines. align-content: center keeps the lines together and places the group in the middle. It does not center the words inside each item.

Example 2 — Space Between the Lines

Pin the first line to the top and the last line to the bottom.

CSS
<style>
  section {
    display: flex;
    flex-wrap: wrap;
    height: 180px;
    align-content: space-between;
    border: 1px solid #ccc;
  }
  div {
    width: 50%;
  }
</style>

<section>
  <div>One</div>
  <div>Two</div>
  <div>Three</div>
  <div>Four</div>
</section>
Try It Yourself

How It Works

  1. Same two lines. One and Two stay on the first row. Three and Four wrap to the second.
  2. Measure the spare height. The 180px box is taller than those two rows.
  3. Pin the edges. space-between puts the first line on the top edge and the last line on the bottom edge.
  4. The gap is the leftover. All spare height sits between the lines, not inside them. space-evenly would also leave a gap above the first line and below the last.

Example 3 — Grid Rows

Spread four grid rows with equal space, including the edges. No flex-wrap.

CSS
<style>
  section {
    display: grid;
    height: 180px;
    align-content: space-evenly;
    border: 1px solid #ccc;
  }
</style>

<section>
  <div>One</div>
  <div>Two</div>
  <div>Three</div>
  <div>Four</div>
</section>
Try It Yourself

How It Works

  1. Switch to grid. display: grid makes one column of rows by default. Each child is its own row.
  2. Leave spare block space. height: 180px is taller than the four rows.
  3. Share that space evenly. space-evenly makes the gap above the first row, between rows, and below the last row the same size.
  4. No wrap property. Grid tracks already exist, so flex-wrap is not part of this rule.

Edge Cases & Pitfalls

If the lines do not move, one of these is usually why.

nowrap

One flex line ignores it

The default is flex-wrap: nowrap. With a single line, align-content has no group of lines to pack. Set flex-wrap: wrap.

space

No spare cross space, no visible change

If the container is only as tall as its lines, every keyword looks the same. Give a row flex a height, or a column flex a width.

items

align-items is a different job

align-items moves items inside one line. align-content moves the lines. Setting both is normal; they do not replace each other.

stretch

stretch needs an auto cross size

A fixed height on the items blocks stretch. Leave the cross size as auto if you want the lines to grow and fill the container.

axis

A column flex flips the axis

With flex-direction: column, the cross axis is horizontal. align-content then packs columns left and right, and it needs spare width.

Browser Support

align-content is a browser layout property for flex, grid, and newer block layout. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Flex since 2015

align-content

Flex: Chrome 29+, Firefox 28+, Safari 9+, Edge 12+. Grid: Chrome 57+, Firefox 52+, Safari 10.1+, Edge 16+. Internet Explorer 11 is flex-only.

96% Flex and grid support
Google Chrome 29+ flex · 57+ grid
Full support
Mozilla Firefox 28+ flex · 52+ grid
Full support
Apple Safari 9+ flex · 10.1+ grid
Full support
Microsoft Edge 12+ flex · 16+ grid
Full support
Opera 16+ flex · grid in Chromium 57+
Full support
Samsung Internet 4+ flex · 6.2+ grid
Full support
Internet Explorer 11 · Old flex only
Partial
align-content Widely supported

Bottom line: Safe for flex and grid in current browsers. Block layout needs Chrome 123, Firefox 125, or Safari 17.4. Firefox does not apply it in multi-column layout. last baseline is not implemented in Chrome, and Safari recognizes that value but does not use it.

Key Takeaways

  • Role: pack or spread flex lines, or grid rows, when the container has spare cross-axis space.
  • Flex requirement: flex-wrap: wrap and a height (for a row). One line does nothing.
  • Not align-items: items move inside a line; content moves the lines.
  • Initial value: normal, which stretches in flex and grid. It is not inherited.

One line: align-content places the lines in the leftover space — after wrap, and after the container is bigger than those lines.

Frequently Asked Questions

It packs or spreads flex lines, or grid rows, along the cross axis when the container is taller than those lines. It does not move items inside a single line.
A flex container with the default flex-wrap: nowrap has only one line, so there is nothing to distribute. You also need leftover space on the cross axis, usually a height larger than the lines.
align-items positions items inside one line. align-content positions the lines themselves inside the container. Use align-items when nothing wraps. Use align-content when you have multiple lines and spare space.
Yes. In a grid it distributes the rows (the block axis) when the grid is taller than those rows. Grid does not need flex-wrap.
No. Set it on the flex or grid container, not on the items. The initial value is normal, which acts like stretch in flex and grid.
Flex support goes back to Chrome 29, Firefox 28, Safari 9, and Edge 12. Grid support starts at Chrome 57, Firefox 52, and Safari 10.1. Internet Explorer 11 only has the old flex behavior. It is a browser layout property, not a Node.js feature.

Next: align-items

Learn how items line up inside a single flex line or grid area.

align-items tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful