CSS align-items Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Flexbox & Grid

What You’ll Learn

The align-items property controls how flex items or grid items are aligned along the cross axis inside their container. It is one of the most useful Flexbox tools for vertically centering content or lining up items of different heights.

01

Cross-Axis Items

Align items inside one row.

02

Syntax

Apply it on the container.

03

Flexbox

Center, stretch, or pin items.

04

CSS Grid

Default alignment for grid items.

05

Baseline

Line up text cleanly.

06

vs align-content

Items, not whole lines.

Definition and Usage

The align-items CSS property sets the default alignment for flex items or grid items on the cross axis. In a row-direction flex container, the cross axis is vertical, so align-items often controls how items sit top-to-bottom inside the row.

It affects every item in the container unless an item overrides it with align-self. This makes it perfect for centering icons beside text, equal-height cards in a row, or baseline-aligned labels.

💡
Beginner Tip

Give the flex container a cross-axis size such as height or min-height when you want vertical alignment like center or flex-end to be visible.

📝 Syntax

Apply align-items to a flex or grid container:

syntax.css
.container {
  align-items: value;
}

Basic Flexbox Example

align-items.css
.container {
  display: flex;
  height: 200px;
  align-items: center;
}

Syntax Rules

  • Set align-items on the flex or grid container, not on individual items.
  • The default value is stretch, which fills the cross-axis size of the flex line.
  • Use align-self on a single item when you need an exception.
  • In a column-direction flex container, the cross axis is horizontal.

⚡ Quick Reference

QuestionAnswer
Initial valuestretch (flexbox), normal (grid)
Applies toFlex containers and grid containers
InheritedNo
AnimatableNo
Common useVertically centering items in a flex row

Default Value

The initial value of align-items is stretch in flexbox. Flex items stretch to fill the container’s cross-axis size unless they have an explicit height or width on that axis.

💎 Property Values

These keyword values control how items align inside a single flex line or grid area.

ValueExampleMeaning
stretchalign-items: stretch;Items stretch to fill the flex line on the cross axis
flex-startalign-items: flex-start;Items align to the start of the cross axis
flex-endalign-items: flex-end;Items align to the end of the cross axis
centeralign-items: center;Items are centered on the cross axis
baselinealign-items: baseline;Items align to their text baselines
normalalign-items: normal;Grid default behavior; in flexbox behaves like stretch
stretch

Default behavior. Items expand to the full height of the flex line.

Flex container
Cross axis
center

Items of different heights are centered along the cross axis.

Flex container
Cross axis
flex-end

Items align to the bottom of the cross axis in a row flex container.

Flex container
Cross axis

align-items vs align-content

PropertyWhat it alignsBest for
align-itemsIndividual items inside one line or trackCentering or stretching items in a single flex row
align-contentWhole lines or tracks as a groupSpacing multiple wrapped rows inside a container

👀 Live Preview

This flex container uses align-items: center to vertically center three items inside a fixed-height row:

Item 1
Item 2
Item 3

Examples Gallery

Try align-items with centered items, stretch, flex-end, and baseline text alignment.

📚 Flexbox Alignment

These examples show how align-items moves items along the cross axis inside a single flex row.

Example 1 — Center Items on the Cross Axis

Center flex items vertically inside a fixed-height container. This is one of the most common Flexbox patterns.

align-items-center.html
<style>
  .container {
    display: flex;
    height: 200px;
    border: 2px solid #ccc;
    align-items: center;
  }
  .item {
    width: 100px;
    height: 50px;
    background: lightblue;
    margin: 10px;
  }
</style>

<div class="container">
  <div class="item">Item 1</div>
  <div class="item">Item 2</div>
  <div class="item">Item 3</div>
</div>
Try It Yourself

How It Works

The container has extra vertical space. align-items: center moves each item to the middle of that space.

Example 2 — Stretch Items to Full Height

With the default stretch value, items grow to fill the container height unless they have a fixed size.

align-items-stretch.css
.toolbar {
  display: flex;
  height: 120px;
  align-items: stretch;
}
.toolbar button {
  flex: 1;
}
Try It Yourself

How It Works

Buttons without a fixed height stretch to match the toolbar’s 120px height.

Example 3 — Align Items to the Bottom

Use flex-end when items should sit at the bottom of the cross axis.

align-items-flex-end.css
.card-row {
  display: flex;
  min-height: 160px;
  align-items: flex-end;
  gap: 1rem;
}
Try It Yourself

How It Works

Each item keeps its own height but sits on the bottom edge of the flex line.

📝 Text & Baseline Alignment

Use baseline when aligning mixed text sizes so the text lines up naturally.

Example 4 — Baseline Alignment for Text

Align items by their text baseline when font sizes differ inside one row.

align-items-baseline.html
<style>
  .label-row {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
  }
  .label-row .large { font-size: 2rem; }
  .label-row .small { font-size: 1rem; }
</style>

<div class="label-row">
  <span class="large">Ag</span>
  <span class="small">Ag</span>
</div>
Try It Yourself

How It Works

Baseline alignment lines up the text bottoms instead of the box edges, which looks more natural for typography.

🧠 How align-items Works

1

The container creates a flex line

Flex items are placed on a line along the main axis. In a row layout, they sit side by side.

Layout
2

align-items picks the cross-axis rule

Values like center, stretch, or baseline set the default alignment for every item.

Alignment
3

Items move within the line

Each item is positioned on the cross axis inside the flex line. Use align-self to override one item.

Items
=

Clean cross-axis alignment

Items line up the way you expect vertically or horizontally, depending on flex direction.

Universal Browser Support

align-items is supported in all modern browsers for both flexbox and CSS Grid layouts.

Baseline · Flexbox & Grid

Cross-axis alignment you can rely on

Chrome, Firefox, Safari, Edge, and Opera all support align-items in current versions.

98% Modern browser support
Google Chrome29+ flex · 57+ grid
Full support
Mozilla Firefox28+ flex · 52+ grid
Full support
Apple Safari9+ flex · 10.1+ grid
Full support
Microsoft Edge12+ flex · 16+ grid
Full support
OperaModern versions
Full support
align-items property 98% supported

Bottom line: Use align-items confidently in modern flexbox and grid layouts.

Conclusion

The align-items property is an essential part of Flexbox and Grid. It gives you a simple way to control how items align on the cross axis inside a single row or grid area.

For beginners, remember: use align-items for individual items, and align-content when you are spacing multiple wrapped lines. Try center for vertical centering and baseline for text.

💡 Best Practices

✅ Do

  • Set a cross-axis size on the container when using center or flex-end
  • Use align-items: center for icon + text rows
  • Use baseline for mixed font sizes in one row
  • Override one item with align-self when needed
  • Pair with justify-content for full alignment control

❌ Don’t

  • Confuse align-items with align-content
  • Expect vertical centering without container height
  • Apply align-items directly to flex items
  • Use stretch when items already have fixed cross-axis sizes
  • Forget that column flex direction swaps the cross axis

Key Takeaways

Knowledge Unlocked

Five things to remember about align-items

Use these points when aligning flex and grid items.

5
Core concepts
📐02

Cross Axis

Often vertical in row flex.

Axis
🛠03

Default

stretch fills the line.

Values
🔄04

Flex + Grid

Works in both layout systems.

Scope
📝05

Baseline

Best for mixed text sizes.

Typography

❓ Frequently Asked Questions

The align-items property controls how flex items or grid items are aligned along the cross axis inside their flex line or grid area.
align-items aligns individual items within one line or track. align-content aligns multiple lines or tracks as a group when extra cross-axis space exists.
The initial value is stretch. Items stretch to fill the flex line or grid area on the cross axis unless they have an explicit size.
Yes. In grid layouts, align-items sets the default alignment for grid items along the block axis inside their grid areas.
Use baseline when aligning text or inline content of different font sizes so their text baselines line up cleanly.

Practice in the Live Editor

Open the HTML editor, build a flex row, and test different align-items values instantly.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful