The align-self
CSS property overrides a grid or flex item's align-items
value. In Grid, it aligns the item inside the grid area. In Flexbox, it aligns the item on the cross axis.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
The property doesn't apply to block-level boxes, or to table cells. If a flexbox item's cross-axis margin is auto
, then align-self
is ignored.
Syntax
/* Keyword values */
align-self: auto;
align-self: normal;
/* Positional alignment */
/* align-self does not take left and right values */
align-self: center; /* Put the item around the center */
align-self: start; /* Put the item at the start */
align-self: end; /* Put the item at the end */
align-self: self-start; /* Align the item flush at the start */
align-self: self-end; /* Align the item flush at the end */
align-self: flex-start; /* Put the flex item at the start */
align-self: flex-end; /* Put the flex item at the end */
/* Baseline alignment */
align-self: baseline;
align-self: first baseline;
align-self: last baseline;
align-self: stretch; /* Stretch 'auto'-sized items to fit the container */
/* Overflow alignment */
align-self: safe center;
align-self: unsafe center;
/* Global values */
align-self: inherit;
align-self: initial;
align-self: unset;
Values
auto
- Computes to the parent's
align-items
value. normal
- The effect of this keyword is dependent of the layout mode we are in:
- In absolutely-positioned layouts, the keyword behaves like
start
on replaced absolutely-positioned boxes, and asstretch
on all other absolutely-positioned boxes. - In static position of absolutely-positioned layouts, the keyword behaves as
stretch
. - For flex items, the keyword behaves as
stretch
. - For grid items, this keyword leads to a behavior similar to the one of
stretch
, except for boxes with an aspect ratio or an intrinsic sizes where it behaves likestart
. - The property doesn't apply to block-level boxes, and to table cells.
- In absolutely-positioned layouts, the keyword behaves like
self-start
- Aligns the items to be flush with the edge of the alignment container corresponding to the item's start side in the cross axis.
self-end
- Aligns the items to be flush with the edge of the alignment container corresponding to the item's end side in the cross axis.
flex-start
- The cross-start margin edge of the flex item is flushed with the cross-start edge of the line.
flex-end
- The cross-end margin edge of the flex item is flushed with the cross-end edge of the line.
center
- The flex item's margin box is centered within the line on the cross-axis. If the cross-size of the item is larger than the flex container, it will overflow equally in both directions.
baseline first baseline
last baseline
- Specifies participation in first- or last-baseline alignment: aligns the alignment baseline of the box’s first or last baseline set with the corresponding baseline in the shared first or last baseline set of all the boxes in its baseline-sharing group. The fallback alignment for
first baseline
isstart
, the one forlast baseline
isend
. stretch
- If the combined size of the items along the cross axis is less than the size of the alignment container and the item is
auto
-sized, its size is increased equally (not proportionally), while still respecting the constraints imposed bymax-height
/max-width
(or equivalent functionality), so that the combined size of allauto
-sized items exactly fills the alignment container along the cross axis. safe
- If the size of the item overflows the alignment container, the item is instead aligned as if the alignment mode were
start
. unsafe
- Regardless of the relative sizes of the item and alignment container, the given alignment value is honored.
Formal definition
Initial value | auto
|
Applies to | flex items, grid items, and absolutely-positioned boxes |
Inherited | no |
Computed value | auto computes to itself on absolutely-positioned elements, and to the computed value of align-items on the parent (minus any legacy keywords) on all other boxes, or start if the box has no parent. Its behavior depends on the layout model, as described for justify-self . Otherwise the specified value.
|
Animation type | discrete |
Formal syntax
auto | normal | stretch | <baseline-position> | <overflow-position>? <self-position>where <baseline-position> = [ first | last ]? baseline<overflow-position> = unsafe | safe<self-position> = center | start | end | self-start | self-end | flex-start | flex-end
Examples
HTML
<section>
<div>Item #1</div>
<div>Item #2</div>
<div>Item #3</div>
</section>
CSS
section {
display: flex;
align-items: center;
height: 120px;
background: beige;
}
div {
height: 60px;
background: cyan;
margin: 5px;
}
div:nth-child(3) {
align-self: flex-end;
background: pink;
}
Result
Specifications
Specification | Status | Comment |
---|---|---|
CSS Box Alignment Module Level 3The definition of 'align-self' in that specification. | Working Draft | Update to latest syntax definitions. |
CSS Flexible Box Layout ModuleThe definition of 'align-self' in that specification. | Candidate Recommendation | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Support in Flex layout
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Supported in Flex Layout |
Chrome Full support 36 Full support 36 Partial support 29 Notes' Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52. Full support 21 Prefixed' Implemented with the vendor prefix: -webkit- |
Edge
Full support 12 |
Firefox Full support 20 Full support 20 Notes' Before Firefox 27, only single-line flexbox is supported. No support 18 — 20 Disabled' From version 18 until version 20 (exclusive): this feature is behind the Prefixed' Implemented with the vendor prefix: -webkit- Full support 48 Prefixed' Implemented with the vendor prefix: -webkit-
Disabled' From version 48: this feature is behind the |
IE
Full support 11 |
Opera
Full support 12.1 |
Safari Full support 9 Full support 9 Full support 6.1 Prefixed' Implemented with the vendor prefix: -webkit- |
WebView Android Full support 37 Full support 37 Partial support 4.4 Notes' Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52. Full support ≤37 Prefixed' Implemented with the vendor prefix: -webkit- |
Chrome Android Full support 36 Full support 36 Partial support 29 Notes' Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52. Full support 25 Prefixed' Implemented with the vendor prefix: -webkit- |
Firefox Android Full support 20 Full support 20 Notes' Before Firefox 27, only single-line flexbox is supported. No support 18 — 20 Disabled' From version 18 until version 20 (exclusive): this feature is behind the Prefixed' Implemented with the vendor prefix: -webkit- Full support 48 Prefixed' Implemented with the vendor prefix: -webkit-
Disabled' From version 48: this feature is behind the |
Opera Android
Full support 12.1 |
Safari iOS Full support 9 Full support 9 Full support 6.1 Prefixed' Implemented with the vendor prefix: -webkit- |
Samsung Internet Android Full support 3.0 Full support 3.0 Partial support 2.0 Notes' Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Samsung Internet 6.0. Full support 1.5 Prefixed' Implemented with the vendor prefix: -webkit- |
baseline
|
Chrome
Full support 57 |
Edge
Full support 79 |
Firefox
Full support 45 |
IE
No support No |
Opera
Full support 44 |
Safari
No support No |
WebView Android
Full support 57 |
Chrome Android
Full support 57 |
Firefox Android
Full support 45 |
Opera Android
Full support 43 |
Safari iOS
No support No |
Samsung Internet Android
Full support 7.0 |
first baseline and last baseline
|
Chrome
Full support 57 |
Edge
Full support 79 |
Firefox
Full support 52 |
IE
No support No |
Opera
Full support 44 |
Safari
No support No |
WebView Android
Full support 57 |
Chrome Android
Full support 57 |
Firefox Android
Full support 52 |
Opera Android
Full support 43 |
Safari iOS
No support No |
Samsung Internet Android
Full support 7.0 |
left and right
|
Chrome
No support No |
Edge
No support No |
Firefox
Full support 52 |
IE
No support No |
Opera
No support No |
Safari
No support No |
WebView Android
No support No |
Chrome Android
No support No |
Firefox Android
Full support 52 |
Opera Android
No support No |
Safari iOS
No support No |
Samsung Internet Android
No support No |
safe and unsafe
|
Chrome No support No No support No Notes' This value is recognized, but has no effect. |
Edge No support No No support No Notes' This value is recognized, but has no effect. |
Firefox
Full support 63 |
IE
No support No |
Opera No support No No support No Notes' This value is recognized, but has no effect. |
Safari No support No No support No Notes' This value is recognized, but has no effect. |
WebView Android No support No No support No Notes' This value is recognized, but has no effect. |
Chrome Android No support No No support No Notes' This value is recognized, but has no effect. |
Firefox Android
Full support 63 |
Opera Android No support No No support No Notes' This value is recognized, but has no effect. |
Safari iOS No support No No support No Notes' This value is recognized, but has no effect. |
Samsung Internet Android No support No No support No Notes' This value is recognized, but has no effect. |
start and end
|
Chrome
Full support 57 |
Edge
Full support 79 |
Firefox
Full support 45 |
IE
No support No |
Opera
Full support 44 |
Safari
No support No |
WebView Android
Full support 57 |
Chrome Android
Full support 57 |
Firefox Android
Full support 45 |
Opera Android
Full support 43 |
Safari iOS
No support No |
Samsung Internet Android
Full support 7.0 |
stretch
|
Chrome
Full support 57 |
Edge
Full support 79 |
Firefox
Full support 52 |
IE
No support No |
Opera
Full support 44 |
Safari
No support No |
WebView Android
Full support 57 |
Chrome Android
Full support 57 |
Firefox Android
Full support 52 |
Opera Android
Full support 43 |
Safari iOS
No support No |
Samsung Internet Android
Full support 7.0 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.'
- See implementation notes.
- User must explicitly enable this feature.'
- User must explicitly enable this feature.
- Requires a vendor prefix or different name for use.'
- Requires a vendor prefix or different name for use.
Support in Grid layout
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Supported in Grid Layout | Chrome
Full support 57 |
Edge
Full support 16 |
Firefox
Full support 52 |
IE Partial support 10 Partial support 10 Prefixed' Implemented with the vendor prefix: -ms-
Notes' Internet Explorer 10 and 11 have the property |
Opera
Full support 44 |
Safari
Full support 10.1 |
WebView Android
Full support 57 |
Chrome Android
Full support 52 |
Firefox Android
Full support 52 |
Opera Android
Full support 43 |
Safari iOS
Full support 10.3 |
Samsung Internet Android
Full support 6.2 |
Legend
- Full support
- Full support
- Partial support
- Partial support
- See implementation notes.'
- See implementation notes.
- Requires a vendor prefix or different name for use.'
- Requires a vendor prefix or different name for use.
See also
- CSS Flexbox Guide: Basic Concepts of Flexbox
- CSS Flexbox Guide: Aligning items in a flex container
- CSS Grid Guide: Box alignment in CSS Grid layouts
- CSS Box Alignment
- The
align-items
property
align-self by Mozilla Contributors is licensed under CC-BY-SA 2.5.