CSS
🎯 CSS align-self Property
The align-self CSS property is used in Flexbox to control the vertical alignment of a single flex item inside a container.
While align-items controls all items, align-self allows you to override alignment for a specific element.
-
📌 Important Difference
- align-items → affects all flex items
- align-self → affects only one selected item
🔹 align-self Syntax
align-self: auto | stretch | center | flex-start | flex-end | baseline;
🔹 align-self Values
1️⃣ auto
The item follows the parent container’s align-items value.
2️⃣ stretch
The item stretches to fill the container height.
3️⃣ center
The item is vertically centered inside the container.
4️⃣ flex-start
The item aligns to the top of the container.
5️⃣ flex-end
The item aligns to the bottom of the container.
6️⃣ baseline
The item aligns based on text baseline.
7️⃣ initial
Resets the property to default (usually auto).
🧩 Example Usage
.container {
display: flex;
align-items: center;
height: 200px;
}
.item1 {
align-self: flex-start;
}
.item2 {
align-self: flex-end;
}
In this example, each item can have its own alignment independent of the other flex items.
-
✔️ Quick Summary
- align-self overrides alignment for a single flex item
- Works independently from align-items
- Useful when one element needs different positioning in Flexbox layouts
