What is align-items?

align-items aligns items along the cross axis of a flex container (vertically in a row) or along the block axis inside each grid area. The default is stretch, which is why flex items in a row become equal height; center is the most common override.

Values

  • stretch (default): items fill the cross axis (unless they have an explicit height or width on that axis).
  • flex-start / start: align to the cross-start edge.
  • flex-end / end: align to the cross-end edge.
  • center: center on the cross axis.
  • baseline: align the first text baselines; great for items with different font sizes, like a big price next to a small label. last baseline also exists.

Related properties

  • align-self on one item overrides align-items for that item.
  • align-content aligns lines of wrapped flex items (or the whole grid), only when there is extra cross-axis space.
  • place-items: center in Grid sets both align-items and justify-items, the shortest way to center.

Common gotchas

  • Using center removes the stretch, so cards in a row no longer have equal heights.
  • In a column direction container, align-items controls horizontal alignment, and stretch makes children full-width; center shrinks them to their content width.
  • Vertical centering needs the container to have a height larger than its content.

Interview tip

Explain why flex rows give equal-height columns by default: that is align-items: stretch at work.

Code example

html
1<style>
2 body { font-family: system-ui; }
3 .row { display: flex; gap: 6px; height: 90px; border: 2px solid #0b1020; margin: 4px 0 12px; padding: 4px; background: #f8fafc; }
4 .row span { background: #2b4bff; color: white; padding: 4px 10px; border-radius: 4px; }
5 .big { font-size: 28px; }
6 .self { align-self: flex-end; background: #e11d48 !important; }
7</style>
8<code>stretch (default)</code>
9<div class="row"><span>A</span><span>B<br>two lines</span><span>C</span></div>
10<code>center</code>
11<div class="row" style="align-items:center"><span>A</span><span>B<br>two lines</span><span>C</span></div>
12<code>baseline</code>
13<div class="row" style="align-items:baseline"><span class="big">$49</span><span>/month</span><span>billed yearly</span></div>
14<code>flex-start + align-self: flex-end on one item</code>
15<div class="row" style="align-items:flex-start"><span>A</span><span class="self">self</span><span>C</span></div>

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.

Open in study app