🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

Align-self

AI & DATA SCIENCE // align-self

The align-self property overrides a flex container's align-items value for one single, individual flex item, letting that one item align differently along the cross axis than its siblings.

Syntax

align-self: auto | stretch | flex-start | flex-end | center | baseline;

Deep Dive Course

align-self accepts the exact same set of values as align-items, but applies to just the individual flex item it's set on, rather than the whole container's items at once — its default value, auto, simply means the item follows its parent's align-items value normally, and setting align-self to anything else on that specific item overrides that inherited default just for it. This is the standard tool for a specific case, like a single 'skip' button that should align to the top of a row while every other button in that same row centers vertically, without needing to restructure the entire container or wrap that one item in an extra nested flex container.

1Understanding Align-self

align-self accepts the exact same set of values as align-items, but applies to just the individual flex item it's set on, rather than the whole container's items at once — its default value, auto, simply means the item follows its parent's align-items value normally, and setting align-self to anything else on that specific item overrides that inherited default just for it. This is the standard tool for a specific case, like a single 'skip' button that should align to the top of a row while every other button in that same row centers vertically, without needing to restructure the entire container or wrap that one item in an extra nested flex container.

💡

Use align-self on a single flex item specifically when just that one item needs different cross-axis alignment than its siblings — restructuring the whole container or its align-items value is unnecessary when only one specific item needs an exception.

editor.html
.row {
  display: flex;
  align-items: flex-start;
}

.highlight {
  align-self: center;
}
localhost:3000

2Practical Example

Here is a real-world application of Align-self showing how it is used in production CSS code.

editor.html
.card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.card-icon {
  align-self: center;
}
localhost:3000

3Best Practices

Follow these guidelines when working with Align-self:

1. Use align-self on an individual flex item for a targeted alignment exception, rather than changing the whole container's align-items or restructuring the layout

2. Remember align-self's default, auto, simply defers to whatever the parent container's align-items value already is

3. Combine align-self: center with margin-top: auto, or similar, sparingly for more nuanced positioning needs beyond align-self's own standard keyword values

⚠️

Tip: Use align-self on a single flex item specifically when just that one item needs different cross-axis alignment than its siblings — restructuring the whole container or its align-items value is unnecessary when only one specific item needs an exception.

editor.html
.row {
  display: flex;
  align-items: flex-start;
}

.highlight {
  align-self: center;
}
localhost:3000

Examples

Example 01Basic Usage
.row {
  display: flex;
  align-items: flex-start;
}

.highlight {
  align-self: center;
}
Example 02Advanced Example
.card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.card-icon {
  align-self: center;
}

Best Practices

  • Use align-self on an individual flex item for a targeted alignment exception, rather than changing the whole container's align-items or restructuring the layout
  • Remember align-self's default, auto, simply defers to whatever the parent container's align-items value already is
  • Combine align-self: center with margin-top: auto, or similar, sparingly for more nuanced positioning needs beyond align-self's own standard keyword values

Interview Question

Why does align-self need to exist as a separate property, rather than simply overriding align-items directly on the container for the one item that needs different alignment?

Hint: Think about what align-items on the container actually controls — the alignment of one single item, or every item within that container collectively.

align-items is specifically a property of the flex container itself, and it sets one single alignment value that's applied uniformly to every flex item within that container at once, it has no built-in mechanism at all for specifying different alignment values for different individual items, since it's fundamentally a container-level, all-items-at-once setting rather than something that can target specific children individually. align-self exists specifically to fill exactly that gap, providing a way to set an alignment value directly on one individual flex item, overriding whatever the container's align-items would otherwise apply to just that one specific item, while leaving every other sibling item completely unaffected and still following the container's original align-items value normally. Without align-self, achieving a single item's different alignment would require restructuring the layout entirely, perhaps wrapping that one item in its own separate nested flex container just to give it independent alignment control, which would be considerably more cumbersome than simply setting one targeted property directly on the item that actually needs to behave differently from its siblings.

Exercises

MediumPractice using Align-self in a real scenario.
View Solution
.row {
  display: flex;
  align-items: flex-start;
}

.highlight {
  align-self: center;
}

Frequently Asked Questions

Why does align-self need to exist as a separate property, rather than simply overriding align-items directly on the container for the one item that needs different alignment?

align-items is specifically a property of the flex container itself, and it sets one single alignment value that's applied uniformly to every flex item within that container at once, it has no built-in mechanism at all for specifying different alignment values for different individual items, since it's fundamentally a container-level, all-items-at-once setting rather than something that can target specific children individually. align-self exists specifically to fill exactly that gap, providing a way to set an alignment value directly on one individual flex item, overriding whatever the container's align-items would otherwise apply to just that one specific item, while leaving every other sibling item completely unaffected and still following the container's original align-items value normally. Without align-self, achieving a single item's different alignment would require restructuring the layout entirely, perhaps wrapping that one item in its own separate nested flex container just to give it independent alignment control, which would be considerably more cumbersome than simply setting one targeted property directly on the item that actually needs to behave differently from its siblings.

Related Functions

Align-itemsJustify-contentFlex-direction