CSS align-content Property

The align-content property controls how content is aligned and distributed along the cross axis of a flex container or the block axis of a grid container.

It also supports alignment in block layout in modern browsers. In flexbox, it distributes flex lines when multiple lines exist. In grid layout, it aligns the grid tracks within the available container space.

align-content Syntax

selector {
  align-content: normal;
}

Replace normal with an alignment value such as start, center, end, space-between, or stretch.

The property also accepts global CSS values including inherit, initial, revert, revert-layer, and unset.

Property Values

Value Description
normal Uses the normal alignment behavior for the layout mode. This is the initial value.
start Packs content toward the start of the alignment axis.
end Packs content toward the end of the alignment axis.
center Centers content along the alignment axis.
flex-start Packs flex lines toward the flex container's cross-start edge.
flex-end Packs flex lines toward the flex container's cross-end edge.
space-between Places the first and last lines or tracks at opposite ends, distributing remaining space between them.
space-around Distributes space around each line or track, with half-sized spaces at the outer edges.
space-evenly Distributes equal space between lines or tracks and at the outer edges.
stretch Stretches eligible lines or tracks to occupy available space.
baseline Aligns content according to the first baseline alignment group.
first baseline Explicitly requests first-baseline alignment.
last baseline Requests last-baseline alignment.
safe center Centers content unless doing so would cause unsafe overflow, in which case start alignment is used.
unsafe center Centers content without the overflow protection provided by safe.

The safe and unsafe keywords can also be combined with other supported positional alignment values.

The property is not inherited. Its initial value is normal.

How align-content Works

The align-content property determines how content is positioned when extra space is available along the relevant alignment axis.

Its behavior depends on the layout mode:

  • Flexbox: Aligns and distributes flex lines along the cross axis. A single-line flex container is not affected.
  • Grid: Aligns the grid's tracks along the block axis when there is available space.
  • Block layout: Can align block content along the block axis in supporting browsers.

For example, align-content: center can group multiple flex lines or grid tracks in the center of a container rather than distributing them across its full height.

Flexbox Alignment

In a flex container, align-content controls the distribution of flex lines along the cross axis. The container must allow wrapping, and multiple flex lines must exist for the property to affect their distribution.

.flex-container {
  display: flex;
  flex-wrap: wrap;
  align-content: space-between;
  width: 260px;
  height: 220px;
  gap: 10px;
}
.flex-item {
  flex: 0 0 110px;
}

With four items, this layout creates two flex lines. The space-between value places the lines toward opposite ends of the container's cross axis, provided enough free space remains.

For a container with only one flex line, use align-items to align the individual items instead.

Grid Alignment

In grid layout, align-content controls the alignment of the grid tracks along the block axis. Unlike flexbox, grid alignment does not require wrapping.

.grid-container {
  display: grid;
  grid-template-columns: repeat(2, 100px);
  grid-template-rows: repeat(2, 50px);
  align-content: center;
  height: 240px;
  gap: 10px;
}

The two grid rows are grouped in the center of the container, with the remaining free space distributed above and below the grid.

If the grid tracks already fill the available block-axis space, there may be no visible change.

Block Layout Alignment

Modern CSS also allows align-content to align content inside certain block containers without changing their display type to flex or grid.

.content-box {
  height: 180px;
  align-content: center;
  border: 1px solid #ccc;
}

In supporting browsers, the block content is centered along the block axis within the available height.

This behavior has newer browser support than traditional flexbox and grid alignment. Older browsers may ignore the property in ordinary block layout.

align-content Example

The following example compares three flex containers with the same items but different align-content values.

<div class="flex-demo start">
  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
  <div class="item">4</div>
</div>

<div class="flex-demo center">
  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
  <div class="item">4</div>
</div>

<div class="flex-demo between">
  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
  <div class="item">4</div>
</div>
.flex-demo {
  display: flex;
  flex-wrap: wrap;
  width: 220px;
  height: 150px;
  gap: 8px;
  padding: 8px;
  border: 1px solid #ccc;
  box-sizing: border-box;
}
.flex-demo .item {
  flex: 0 0 80px;
  height: 36px;
  background-color: #1769aa;
  color: #fff;
  text-align: center;
  line-height: 36px;
}
.flex-demo.start {
  align-content: flex-start;
}
.flex-demo.center {
  align-content: center;
}
.flex-demo.between {
  align-content: space-between;
}

Each container contains two rows of items. The difference is how those rows are positioned vertically within the available space.

Browser Result

flex-start

1
2
3
4

center

1
2
3
4

space-between

1
2
3
4

The flex-start value groups the rows at the top, center groups them in the middle, and space-between places the rows toward opposite ends of the container.

align-content vs. align-items

Although both properties control alignment, they operate on different parts of a layout.

Property Purpose
align-content Aligns flex lines or grid tracks as a group within the container's available space.
align-items Sets the default alignment of individual flex or grid items within their lines or grid areas.

In flexbox, use align-items for the alignment of items within each flex line and align-content to distribute multiple flex lines.

In grid layout, align-items aligns individual grid items within their grid areas, while align-content positions the grid tracks within the container.

Browser Support

The align-content property is widely supported for flexbox and grid layouts in modern browsers, including Chrome, Edge, Firefox, and Safari.

Support for align-content in ordinary block layout is newer. Visit Can I Use? to check current browser compatibility, including block layout support.

Specifications

The align-content property is defined in the CSS Box Alignment Module Level 3 specification.

CSS Box Alignment Module Level 3