CSS align-items
The CSS align-items property specifies the default align-self value for all boxes (including anonymous boxes) participating in this box's formatting context.
The alignment is similar to justify-content but in the perpendicular direction.
To align individual items, use the align-self property. This will override the align-items property for the specified flex or grid item with which it is applied.
Syntax
Possible Values
normal- The default value. Behaves as
stretchfor flex containers, andstretchorstartfor grid containers depending on the box. flex-start- The cross-start margin edge of the flex item is placed flush with the cross-start edge of the line.
flex-end- The cross-end margin edge of the flex item is placed flush with the cross-end edge of the line.
center- The item's margin box is centered in the cross axis within the line. (If the cross size of the flex line is less than that of the flex item, it will overflow equally in both directions.)
baseline-
All items are aligned such that their baselines align. The item with the largest distance between its baseline and its cross-start margin edge is placed flush against the cross-start edge of the line.
If the item's inline axis is the same as the cross axis, this value is identical to
flex-start. stretch- Items are stretched such as the cross-size of the item's margin box is the same as the line while still respecting
min-height,min-width,max-height, andmax-heightconstraints. start- Items are packed toward the start edge of the alignment container.
end- Items are packed toward the end edge of the alignment container.
self-start- Items are packed flush to the edge of the alignment container of the start side of the item.
self-end- Items are packed flush to the edge of the alignment container of the end side of the item.
In addition, all CSS properties also accept the following CSS-wide keyword values as the sole component of their property value:
initial- Represents the value specified as the property's initial value.
inherit- Represents the computed value of the property on the element's parent.
unset- This value acts as either
inheritorinitial, depending on whether the property is inherited or not. In other words, it sets all properties to their parent value if they are inheritable or to their initial value if not inheritable.
Basic Property Information
- Initial Value
normal- Applies To
- Flex containers and grid containers.
- Inherited?
- No
- Media
- Visual
- Computed Value
- Specified value
- Animatable
- No
Example Code
Basic CSS
Working Example within an HTML Document
About Flexbox
Flexbox refers to the Flexible Box Layout module introduced in CSS3. Flex items are placed within a flex container. A flex container is an element with either display: flex or display: inline-flex.
In the flex layout model, the children of a flex container can be laid out in any direction, and can "flex" their sizes, either growing to fill unused space or shrinking to avoid overflowing the parent.
For more information on flex items, see the flex property.
CSS Specifications
- The
align-itemsproperty is defined in CSS Box Alignment Module Level 3 (W3C Working Draft). - It was originally defined in the CSS Flexible Box Layout Module Level 1 (W3C Candidate Recommendation).
Browser Support
Browser support for CSS properties can vary, particularly for newer or experimental features. Check current browser compatibility before using a property in production, especially when supporting older browsers.
The following table provided by Caniuse.com shows the level of browser support for this feature.
Initial Value
CSS properties have an initial value that applies when the property has not been explicitly set. The initial value is different from the value inherited from a parent element and may vary between properties.
Inheritance
Some CSS properties inherit their computed value from their parent element by default, while others do not. The inherit, initial, unset, and revert keywords can also be used to control how a property gets its value.
Vendor Prefixes
Most modern CSS properties use the standard, unprefixed syntax. Vendor-prefixed properties such as -webkit- are mainly relevant to older browser versions or specific features and should only be used when required by your browser support targets.