CSS align-items: compare stretch, center, and baseline
Flexbox align-items aligns items along the cross axis within each flex line. In horizontal writing, that axis is vertical for row and horizontal for column. Set the default on the parent. To move one item differently, apply align-self to that item.
Distinguish the cross axis and five alignment values
| Value | Cross-axis behavior |
|---|---|
stretch |
Stretch if the cross size is auto, within size limits |
flex-start |
Align to the cross-axis start |
flex-end |
Align to the cross-axis end |
center |
Center each item on the cross axis |
baseline |
Align the text baselines |
The cross axis is perpendicular to the axis along which items are placed. See the flex-direction guide to axes for what changes with direction, and the justify-content example for main-axis alignment for main-axis alignment. stretch acts on items whose cross size is automatic, subject to minimum and maximum sizes and auto margins. See CSS Flexbox · Cross-axis Alignment. For flex items, normal behaves like stretch.
Run the box height and baseline comparison
Save the code as align-items.html and open it. The items use font sizes of 14px, 22px, and 30px, with no set heights. The thin yellow marks help you compare their text baselines. No other files are needed.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Compare cross-axis alignment and baselines</title>
<style>
body { margin: 20px; font: 16px/1.6 system-ui, sans-serif; color: #203348; }
* { box-sizing: border-box; }
h1 { font-size: 24px; }
h2 { margin: 14px 0 6px; font-size: 16px; }
.samples { max-width: 560px; }
.box { display: flex; gap: 12px; height: 110px; padding: 10px;
border: 1px solid #84a3b7; background: #edf4f8; }
.item { flex: none; padding: 8px; line-height: 1.3;
color: white; background: #176b86; }
.item:nth-child(1) { font-size: 14px; }
.item:nth-child(2) { font-size: 22px; }
.item:nth-child(3) { font-size: 30px; }
.mark { display: inline-block; width: 8px; height: 0;
border-top: 1px solid #f3ce5b; }
.stretch { align-items: stretch; }
.flex-start { align-items: flex-start; }
.flex-end { align-items: flex-end; }
.center { align-items: center; }
.baseline { align-items: baseline; }
</style>
</head>
<body>
<h1>Compare align-items values</h1>
<div class="samples">
<h2>stretch</h2>
<div class="box stretch">
<div class="item">A<i class="mark" aria-hidden="true"></i></div>
<div class="item">B<i class="mark" aria-hidden="true"></i></div>
<div class="item">C<i class="mark" aria-hidden="true"></i></div>
</div>
<h2>flex-start</h2>
<div class="box flex-start">
<div class="item">A<i class="mark" aria-hidden="true"></i></div>
<div class="item">B<i class="mark" aria-hidden="true"></i></div>
<div class="item">C<i class="mark" aria-hidden="true"></i></div>
</div>
<h2>flex-end</h2>
<div class="box flex-end">
<div class="item">A<i class="mark" aria-hidden="true"></i></div>
<div class="item">B<i class="mark" aria-hidden="true"></i></div>
<div class="item">C<i class="mark" aria-hidden="true"></i></div>
</div>
<h2>center</h2>
<div class="box center">
<div class="item">A<i class="mark" aria-hidden="true"></i></div>
<div class="item">B<i class="mark" aria-hidden="true"></i></div>
<div class="item">C<i class="mark" aria-hidden="true"></i></div>
</div>
<h2>baseline</h2>
<div class="box baseline">
<div class="item">A<i class="mark" aria-hidden="true"></i></div>
<div class="item">B<i class="mark" aria-hidden="true"></i></div>
<div class="item">C<i class="mark" aria-hidden="true"></i></div>
</div>
</div>
</body>
</html>
With stretch, the items fill the 88px inner height after padding and borders. flex-start aligns their top edges and flex-end their bottom edges. center centers each box, while baseline lines up the text. The top edges can differ because the text sizes differ.
Check when items stretch and how to override one
Add the rules below at the end of the stylesheet. The items in the first row now have a set height of 70px, which stretch does not increase. In the center row, only the last item moves to the bottom. Remove the two rules to restore the original layout.
.stretch .item {
height: 70px;
}
.center .item:last-child {
align-self: flex-end;
}
If alignment does not change, inspect each item’s width or height, minimum and maximum sizes, and computed align-self. Auto margins on the cross axis take free space before alignment. For instance, margin-top: auto can push an item down in a horizontal flex row. See CSS Flexbox · Auto Margins.
Check the alignment axis in columns and wrapped rows
Add the next rule and the same center value centers a vertical stack horizontally. If an item already takes the full width through width: 100%, there may be no space to see that movement. Remove the added rule after comparing.
.center {
flex-direction: column;
height: 240px;
align-items: center;
}
When flex-wrap creates multiple lines, align-items positions the items inside each line. align-content positions the lines themselves across the cross axis. Check the space around or between whole lines if you want to adjust the line group. See CSS Flexbox · Packing Flex Lines.




