CSS align-items Property

The align-items property sets the default alignment of flexbox and grid items along the cross axis or block axis of their container.

In flexbox, it aligns items along the cross axis of each flex line. In grid layout, it controls how items are positioned within their grid areas along the block axis. Individual items can override this alignment using the align-self property.

align-items Syntax

selector {
  align-items: normal;
}

Replace normal with an alignment value such as start, center, end, stretch, or baseline.

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

Property Values

Value Description
normal Uses the default alignment behavior for the layout mode. This is the initial value.
stretch Stretches eligible items to fill the available space along the alignment axis, subject to their sizing constraints.
start Aligns items toward the start of the alignment axis.
end Aligns items toward the end of the alignment axis.
center Centers items along the alignment axis.
flex-start Aligns flex items toward the cross-start edge of their flex line.
flex-end Aligns flex items toward the cross-end edge of their flex line.
self-start Aligns each item toward its own start side along the alignment axis.
self-end Aligns each item toward its own end side along the alignment axis.
baseline Aligns items using their first baseline alignment group.
first baseline Explicitly requests first-baseline alignment.
last baseline Aligns items using their last baseline alignment group.
safe center Centers items unless doing so would cause unsafe overflow, in which case start alignment is used.
unsafe center Centers items 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, which behaves similarly to stretch for most flex items and many grid items.

How align-items Works

The align-items property is applied to a flex or grid container and sets the default alignment for its items.

Its behavior depends on the layout mode:

  • Flexbox: Aligns items along the cross axis of each flex line. In a row-direction flex container, this is usually vertical. In a column-direction flex container, it is usually horizontal.
  • Grid: Aligns items within their grid areas along the block axis, which is usually vertical in horizontal writing modes.

For example, align-items: center centers flex items across the cross axis or centers grid items within their individual grid areas.

Items can use align-self to override the alignment established by their container.

Flexbox Alignment

In flexbox, align-items controls how items are positioned along the cross axis within each flex line.

.flex-container {
  display: flex;
  align-items: center;
  height: 180px;
  gap: 10px;
}
.flex-item {
  padding: 12px;
  background-color: #1769aa;
  color: #fff;
}

The flex items are centered vertically within the container when the flex direction is row and the writing mode is horizontal.

Unlike align-content, this property works with a single flex line. It aligns individual items rather than distributing multiple lines.

Grid Alignment

In grid layout, align-items sets the default block-axis alignment of items within their grid areas.

.grid-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: 120px;
  align-items: end;
  gap: 10px;
}
.grid-item {
  padding: 12px;
  background-color: #1769aa;
  color: #fff;
}

Each grid item is aligned toward the end of its grid area along the block axis. In a typical horizontal writing mode, this places the items near the bottom of the row.

The stretch value can make auto-sized grid items fill the available block-axis space, while values such as start, center, and end position them without stretching.

align-items Example

The following example compares three flex containers using flex-start, center, and flex-end.

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

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

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

Each container has the same three items. The only difference is their alignment along the cross axis.

Browser Result

flex-start

1
2
3

center

1
2
3

flex-end

1
2
3

The flex-start value places items at the top, center centers them vertically, and flex-end places them at the bottom of the container.

align-items vs. align-content

These properties both control alignment but apply to different aspects of flexbox and grid layout.

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

Use align-items to position items within their lines or areas. Use align-content when you need to position or distribute multiple flex lines or grid tracks.

Browser Support

The align-items property is widely supported in modern browsers, including Chrome, Edge, Firefox, and Safari. Common flexbox and grid alignment values are broadly available, although support for some advanced alignment keywords may vary.

Visit Can I Use? to check current browser compatibility.

Specifications

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

CSS Box Alignment Module Level 3