CSS Flexbox align-self: align one item on the cross axis
To give one flex item a different position on the cross axis, set align-self on that item. The parent’s align-items is the default, and align-self: auto uses that default. In horizontal writing, the cross axis is vertical for row and horizontal for column.
Set the parent’s default and the item’s override
In the snippet, align-items: center goes on the parent and align-self: flex-end on the exception. If the card sits inside a wrapper, set it on the wrapper that directly participates in Flexbox. Applying it to an inner element does not align the wrapper alongside its siblings.
.container {
display: flex;
align-items: center;
}
.item-special {
align-self: flex-end;
}
| Value | Result in this example |
|---|---|
auto |
Uses the parent’s align-items: center. |
flex-start |
Sits at the top edge. |
center |
Centers vertically within the line. |
flex-end |
Sits at the bottom edge. |
stretch |
Fills the line when its height is auto and size or margin constraints allow it. |
The table uses the full example’s parent with align-items: center. The value auto uses the parent’s align-items, for cross-axis alignment. Use baseline to line up text baselines. It produces a different result from flex-end, which aligns box edges. See CSS Box Alignment · align-self.
Compare five alignments in one row
Save the code as flex-align-self.html and open it. No external files or JavaScript are needed. Subtract 26px of borders and padding from the parent’s 240px border box to get a 214px-tall flex line. For an item whose one-line label fits in a 44px box, a centered item starts 85px from the inner top edge. The start item is at 0px, the end item at 170px, and the stretch item fills the 214px.
<!doctype html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Compare Flexbox align-self values</title>
<style>
body { margin: 20px; font: 16px/1.6 system-ui, sans-serif; color: #203348; }
* { box-sizing: border-box; }
h1 { font-size: 24px; }
.demo { display: flex; align-items: center; gap: 8px;
max-width: 620px; height: 240px; padding: 12px;
border: 1px solid #7795a3; background: #edf5f7; }
.item { flex: 1 1 0; min-width: 0; min-height: 44px; padding: 10px 4px;
background: #176f80; color: white; font-size: 14px; text-align: center;
overflow-wrap: anywhere; border-radius: 4px; }
.start { align-self: flex-start; }
.center { align-self: center; }
.end { align-self: flex-end; }
.stretch { align-self: stretch; }
</style>
</head>
<body>
<h1>Compare align-self values</h1>
<div class="demo">
<div class="item auto">auto</div>
<div class="item start">Start</div>
<div class="item center">Center</div>
<div class="item end">End</div>
<div class="item stretch">Stretch</div>
</div>
<p>The parent sets align-items to center. The first item follows it, and the other items use their own align-self values.</p>
</body>
</html>
Change only the parent’s align-items to flex-start. The first, automatic item moves up, while the explicit center item stays centered. Restore the parent’s center after comparing. The position of each box is independent of the vertical alignment of the text inside it.
Diagnose stretch and center when they seem ineffective
Add the fixed height rule below at the end of style. Now the last item has a 60px cross size, so it no longer stretches to 214px. A constraint such as max-height can also limit stretching. Remove the added rule after the test.
.stretch {
height: 60px;
}
Now add the margin rule below to the centered item. The top auto margin absorbs the extra space on the cross axis and pushes the item down. Its align-self: center does not determine the position in this case. Remove the rule to restore centering. See CSS Flexbox · Auto margins.
.center {
margin-top: auto;
}
With the original example restored, set the parent’s height to auto. Its height follows the tallest item. If all items are the same height, there may be no visible difference between start, center, and end. When troubleshooting, inspect the line size, the item’s height, and its cross-axis margins in developer tools. Restore 240px afterward.
Find the alignment axis in columns and wrapped layouts
Append the rules below to switch to column, where the cross axis is horizontal. The auto and center items are horizontally centered. Start and end are at the left and right. The last item is allowed to stretch horizontally because its width is set back to auto. The physical start and end can change with the writing direction. See CSS Flexbox · flex-direction.
.demo {
flex-direction: column;
height: auto;
min-height: 340px;
}
.item {
flex: 0 0 auto;
width: 60px;
}
.stretch {
width: auto;
}
When flex-wrap creates multiple lines, align-self aligns an item inside its own line. Use align-items for the default within each line and align-content to position the lines as a group. align-content has no effect on a single-line nowrap container. See CSS Flexbox · align-content.




