Free tools Windows power users keep installed
One-click scans. No signup required.
align-items sets the default alignment for the direct children of a flex or grid container. In Flexbox, it aligns items along the cross axis; in Grid, it aligns each item along the block axis inside its grid area. The right value depends on the layout, the item’s size, and whether you want to position it or stretch it.
What does align-items do?
Use align-items on a flex or grid container to set how its direct children align. It supplies the group default: an individual child can use align-self to override that rule. The property does not align every descendant automatically; it applies to the container’s items.
The axis differs by layout. In Flexbox, align-items controls the cross axis, perpendicular to the main axis. In Grid, it aligns items along the block axis within their grid areas. Physical directions depend on writing mode and layout direction, so logical values such as start and end are not always equivalent to top, bottom, left, or right. See MDN’s box alignment overview and the CSS Box Alignment Module Level 3.
How to center items with align-items
For a row flex container, the cross axis is vertical in the usual horizontal writing mode. align-items: center centers the items vertically within the flex line. In a column flex container, the cross axis is horizontal, so the same declaration centers items horizontally, not vertically.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
/* Center toolbar children on the cross axis. */
.toolbar {
display: flex;
align-items: center;
}
/* Centering on both axes in a row flex container. */
.panel {
display: flex;
justify-content: center; /* main axis */
align-items: center; /* cross axis */
}
Flexbox’s main and cross axes change with flex-direction. To center in both dimensions, choose a value for justify-content on the main axis as well as align-items on the cross axis.
What each value does
| Value | Effect | Useful when |
|---|---|---|
normal |
The initial value. In Flexbox it behaves like stretch. In Grid it is similar to stretch, except items with intrinsic sizing or an aspect ratio behave like start. |
You want the layout’s default alignment behavior. |
stretch |
Expands an item with an automatic size toward the available cross-size, subject to its width and height constraints. If the item is not auto-sized, it falls back to start-side alignment. | Items should fill available space when their sizing allows it. |
center |
Centers the item’s margin box within the relevant alignment area. An item larger than a flex container can overflow equally on both sides. | You want centered positioning rather than expansion. |
start / end |
Aligns items to the logical start or end edge of the alignment container in the relevant axis. | You want an edge alignment that follows writing direction. |
self-start / self-end |
Aligns to the start or end side corresponding to the item itself. | Items’ own writing directions matter to the alignment. |
baseline, first baseline, last baseline |
Aligns items by their typographic baselines. | Text or mixed-size content should share a baseline. |
flex-start / flex-end |
Uses Flexbox-specific axis terminology; outside a flex formatting context, these behave like start and end. |
You need the flex-axis-specific terms in a Flexbox rule. |
safe center / unsafe center |
safe can fall back to start alignment if centering would cause overflow that loses content. unsafe honors centering even when overflow could make content inaccessible. |
Overflow could hide important content. |
MDN also lists anchor-center for anchor-positioned elements; it aligns an element to its associated anchor in the block direction. It is a specialized, newer value rather than a routine choice, so check current browser support before relying on it. MDN describes align-items as widely available since September 2015, while noting that support can vary for some parts of the feature. Check compatibility for the specific value and browsers you target in the MDN property reference, last modified 2026-08-21.
Rank #2
Why does align-items stretch items?
The initial value is normal, which behaves like stretch in Flexbox. Stretching affects items whose relevant size is automatic: the browser expands their used size toward the available cross-size, while respecting size limits such as min-width, max-width, min-height, and max-height. An explicitly sized item does not stretch in the same way; stretch falls back to start-side alignment.
To stop auto-sized children from filling the available cross-size, set a positioning value such as start or center. In Grid, remember that normal has an exception: items with intrinsic sizing or an aspect ratio behave like start, rather than stretching as ordinary items do.
Rank #3
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Using align-items in Grid
In Grid, the property aligns items on the block axis within their grid areas. For example, this places items at the block-start edge of their areas:
.cards {
display: grid;
align-items: start;
}
Grid’s block axis follows the writing mode; it should not be assumed to mean a fixed physical direction in every document. Use justify-items for the other, inline axis in common Grid layouts.
Quick Recap
Best Value
Rank #4
How it differs from related alignment properties
align-items: establishes the alignment default for a container’s items—cross axis in Flexbox, block axis in Grid.align-self: overrides that default for one item.align-content: aligns or distributes content or lines as a group in layout contexts where it applies; it is not the per-item default set byalign-items.justify-contentandjustify-items: address the other axis in their respective layout contexts—main axis for Flexbox and, commonly, inline-axis alignment or distribution in Grid.
Quick examples
Center a row’s children vertically
.toolbar {
display: flex;
flex-direction: row;
align-items: center;
}
Align grid cards to the start of their areas
.cards {
display: grid;
align-items: start;
}
Override one grid item
.cards__featured {
align-self: center;
}
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

