CSS align-self
Property
The align-self
property in CSS controls how a specific flex or grid item aligns itself along the cross-axis, overriding align-items
for that item only.
1. Syntax
2. Accepted Values
Value | Description |
---|---|
auto (default) | Inherits from align-items (if in a flex/grid container). |
flex-start | Aligns the item to the start of the cross-axis. |
flex-end | Aligns the item to the end of the cross-axis. |
center | Centers the item along the cross-axis. |
baseline | Aligns the item’s text baseline with others. |
stretch | Stretches the item to fill the container (if no fixed height/width). |
3. Example – Align Items Differently in Flexbox
✅ Each box aligns differently within the same flex container.
4. Example – align-self
in CSS Grid
✅ Works the same way in CSS Grid!
5. Best Practices
✔ Use align-self
when only one item needs a different alignment.
✔ Avoid stretch
for fixed-size elements to prevent unwanted scaling.
✔ Use baseline
for text-heavy layouts.