CSS

🎯 CSS align-items Property

The align-items CSS property is used in Flexbox to control how flex items are aligned along the cross axis (vertical alignment in row direction).

It allows you to position items at the top, center, bottom, or stretch them inside a flex container.

  • 📌 Important Note

  • If flex-direction: row → align-items controls vertical alignment.
  • If flex-direction: column → align-items controls horizontal alignment.

🔹 align-items Syntax

CSS

align-items: stretch | center | flex-start | flex-end | baseline;
                

🔹 align-items Values

1️⃣ stretch

Default value. Items stretch to fill the container’s height.

2️⃣ center

Items are centered vertically inside the container.

3️⃣ flex-start

Items are aligned at the top of the container.

4️⃣ flex-end

Items are aligned at the bottom of the container.

5️⃣ baseline

Items are aligned based on text baseline alignment.

6️⃣ initial

Resets the property to default (stretch).

🧩 Example Usage

CSS

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

.item {
    width: 50px;
    height: 50px;
}
                

In this example, all flex items are vertically centered inside the container.

  • ✔️ Quick Summary

  • stretch → Items fill the container
  • center → Items are centered
  • flex-start → Align to top
  • flex-end → Align to bottom
  • Used for cross-axis alignment in Flexbox layouts