CSS align-content Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Flexbox & Grid

What You’ll Learn

The align-content property controls how multiple lines in a flex container, or multiple tracks in a grid container, are distributed along the cross axis when extra space is available. It is a layout property that helps you position whole rows or tracks, not individual items inside one row.

01

Cross-Axis Lines

Move whole lines or tracks.

02

Syntax

One property, many keywords.

03

Flexbox

Works with wrapped flex lines.

04

CSS Grid

Also distributes grid tracks.

05

Spacing Values

center, between, evenly, and more.

06

Common Pitfalls

Know when it has no effect.

Definition and Usage

The align-content CSS property sets how a flex container’s lines are aligned within the flex container when there is extra space on the cross axis. In a grid container, it does the same job for grid tracks.

Think of it this way: if a flex container wraps items into multiple rows, align-content decides where those rows sit inside the container’s height. It does not align one item inside a row — that is the job of align-items.

💡
Beginner Tip

Use align-content only when your container has extra cross-axis space and more than one line or track. Give the container a fixed height in flexbox, or use a grid with fewer tracks than the available space.

📝 Syntax

Apply align-content to a flex or grid container:

syntax.css
.container {
  align-content: value;
}

Basic Flexbox Example

align-content.css
.container {
  display: flex;
  flex-wrap: wrap;
  height: 200px;
  align-content: center;
}

Syntax Rules

  • Apply align-content to a flex or grid container, not to individual items.
  • In flexbox, the container usually needs flex-wrap: wrap and a cross-axis size such as height.
  • It only has a visible effect when there is extra cross-axis space and more than one line or track.
  • Use keyword values like center, space-between, and space-evenly.

⚡ Quick Reference

QuestionAnswer
Initial valuestretch
Applies toFlex containers and grid containers
InheritedNo
AnimatableNo
Common useSpacing wrapped flex rows or grid tracks on the cross axis

Default Value

The initial value of align-content is stretch. When extra cross-axis space exists, lines or tracks stretch to fill that space.

💎 Property Values

These keyword values control how lines or tracks are packed and spaced inside the container.

ValueExampleMeaning
stretchalign-content: stretch;Lines stretch to use the remaining cross-axis space
centeralign-content: center;Lines are packed toward the center of the container
flex-startalign-content: flex-start;Lines are packed toward the start of the cross axis
flex-endalign-content: flex-end;Lines are packed toward the end of the cross axis
space-betweenalign-content: space-between;Even spacing between lines; first and last lines touch the edges
space-aroundalign-content: space-around;Even spacing around each line, including partial space at the edges
space-evenlyalign-content: space-evenly;Equal space between all lines, including the edges
stretch

Default behavior. Lines expand to fill the container height.

Flex container
Cross axis
center

All lines move to the middle of the cross axis.

Flex container
Cross axis
space-between

First line at the top, last line at the bottom, equal gaps between lines.

Flex container
Cross axis

When align-content Applies

align-content is useful in these situations:

  • Flexbox with wrapping — The container uses display: flex, flex-wrap: wrap, and has a defined cross-axis size such as height.
  • Multiple flex lines — Items wrap into more than one line, leaving extra space on the cross axis.
  • CSS Grid — The grid container has extra space along the block axis and multiple tracks to distribute.
  • Not for single-line flex rows — If all items stay on one line, use align-items instead.

align-content vs align-items

PropertyWhat it alignsBest for
align-contentWhole lines or tracks as a groupSpacing multiple rows or grid tracks inside a container
align-itemsIndividual items inside one line or trackVertical alignment of items within a single row

👀 Live Preview

This flex container wraps six items into multiple rows and uses align-content: center to group them in the middle of the container height:

1
2
3
4
5
6

Examples Gallery

Try align-content with centered lines, spaced rows, and a grid layout.

📚 Flexbox Layouts

Use align-content when wrapped flex items create multiple rows and you want to control how those rows sit inside the container.

Example 1 — Center Multiple Flex Lines

This example centers wrapped flex items as a group inside a fixed-height container.

align-content-center.html
<style>
  .container {
    display: flex;
    flex-wrap: wrap;
    height: 200px;
    align-content: center;
    border: 1px solid #000;
  }
  .item {
    flex: 0 0 30%;
    margin: 5px;
    height: 50px;
    background: lightblue;
  }
</style>

<div class="container">
  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
  <div class="item">4</div>
  <div class="item">5</div>
  <div class="item">6</div>
</div>
Try It Yourself

How It Works

Because the container has a fixed height and wrapped rows, align-content: center moves the group of rows to the vertical center.

Example 2 — Space Rows with space-between

Use this when you want the first row at the top, the last row at the bottom, and equal gaps between rows.

align-content-between.css
.card-grid {
  display: flex;
  flex-wrap: wrap;
  height: 240px;
  align-content: space-between;
}
Try It Yourself

How It Works

space-between distributes free space only between the rows, not before the first row or after the last row.

Example 3 — Even Spacing with space-evenly

This value creates equal spacing between rows and at the top and bottom edges.

align-content-evenly.css
.gallery {
  display: flex;
  flex-wrap: wrap;
  min-height: 220px;
  align-content: space-evenly;
}
Try It Yourself

How It Works

Unlike space-between, space-evenly leaves the same amount of space before the first row and after the last row.

🚀 CSS Grid Layouts

In grid containers, align-content distributes tracks along the block axis when the grid is shorter than its container.

Example 4 — Align Grid Tracks

align-content also works in CSS Grid when the grid container has extra block-axis space.

align-content-grid.css
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 60px);
  height: 260px;
  align-content: center;
  gap: 10px;
}
Try It Yourself

How It Works

The grid tracks stay grouped in the center of the container instead of stretching to fill the full height.

🧠 How align-content Works

1

Items wrap into lines or tracks

In flexbox, wrapped items form multiple rows. In grid, explicit tracks define rows or columns.

Layout
2

Extra cross-axis space appears

When the container is taller or wider than the combined lines or tracks, free space remains on the cross axis.

Condition
3

align-content distributes the lines

Values like center, space-between, and stretch position the whole group of lines or tracks.

Alignment
=

Balanced multi-row layouts

Whole rows or tracks move together, while align-items still handles item alignment inside each row.

Universal Browser Support

align-content is widely supported in all modern browsers for both flexbox and CSS Grid layouts.

Baseline · Flexbox & Grid

Reliable layout support across browsers

From current Chrome and Safari builds to Firefox and Edge, align-content is a stable tool for modern responsive layouts.

98% Modern browser 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 Modern versions
Full support

Legacy notes

Very old browsers may support flexbox align-content but not grid alignment.

💻
Internet Explorer IE 10–11 flex only · No grid align-content
Partial
align-content property 98% supported

Bottom line: Use align-content confidently in modern flexbox and grid layouts.

Conclusion

The align-content property is an essential tool for flexbox and grid layouts. It gives you control over how multiple lines or tracks are distributed along the cross axis when extra space is available.

For beginners, remember the key idea: align-content moves whole rows or tracks, while align-items aligns items inside one row. Experiment with values like center, space-between, and space-evenly to see how they change your layout.

💡 Best Practices

✅ Do

  • Give flex containers a cross-axis size when you want visible alignment
  • Use flex-wrap: wrap when you expect multiple lines
  • Pair align-content with justify-content for full layout control
  • Test spacing values like space-between and space-evenly
  • Use align-items for item alignment inside a single row

❌ Don’t

  • Expect align-content to work on a single-line flex row
  • Confuse it with align-items or justify-content
  • Forget to set a container height in flexbox demos
  • Assume every layout needs align-content
  • Skip testing on small screens where wrapping changes line count

Key Takeaways

Knowledge Unlocked

Five things to remember about align-content

Use these points when building flex and grid layouts.

5
Core concepts
📐 02

Cross Axis

Works when extra space exists.

Axis
🛠 03

Default

stretch fills the space.

Values
🔄 04

Flex + Grid

Useful in both layout systems.

Scope
💡 05

Not align-items

Different job, different result.

Compare

❓ Frequently Asked Questions

The align-content property controls how multiple lines in a flex container, or multiple tracks in a grid container, are distributed along the cross axis when there is extra space available.
align-items aligns individual items inside a single line or track. align-content aligns the lines or tracks themselves as a group inside the container.
It only works when the container has extra space on the cross axis and more than one line or track. If everything fits in one line, align-content does nothing.
The initial value is stretch. Lines or tracks stretch to fill the available cross-axis space.
Yes. In grid layouts, align-content distributes grid tracks along the block axis when the grid container has extra space.

Practice in the Live Editor

Open the HTML editor, build a flex layout, and test different align-content values instantly.

HTML Editor →

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.

5 people found this page helpful