Skip to main content
Home / CSS Almanac / Properties / A / align-items

align-items

The align-items property is related to CSS layout. It effects how elements are aligned both in Flexbox and Grid layouts.

align-items: flex-start | flex-end | center | baseline | stretch

.container {
  display: flex;
  align-items: flex-start;
}

The align-items property defines the default behavior for how items are laid out along the cross axis (perpendicular to the main axis).

Imagine a horizontal flexbox layout. That horizontal flow is the main axis, so align-items is the alignment opposite that, on the vertical axis. Bear in mind that changes when the main axis changes, and the cross axis changes with it.

You can think of align-items as the justify-content version for the cross-axis (perpendicular to the main-axis).

The rest of this article is fairly focused on flexbox rather than grid. The concepts are still very similar, but there are some differences. For example, in flexbox, the axises can change, where in grid they cannot. That effects things like flexbox having values like flex-start where in grid it is just start.

The align-items property accepts 5 different values:

  • flex-start: cross-start margin edge of the items is placed on the cross-start line
  • flex-end: cross-end margin edge of the items is placed on the cross-end line
  • center: items are centered in the cross-axis
  • baseline: items are aligned such as their baselines align
  • stretch (default): stretch to fill the container (still respect min-width/max-width)

The following figure helps understand how flex items are layed out depending on the align-items value.

from w3.org

Demo

The following demo shows how flex items are layed out depending on the align-items value:

  • The red list is set to flex-start
  • The yellow list is set to flex-end
  • The blue list is set to center
  • The green list is set to baseline
  • The pink list is set to stretch
Check out this Pen!

Related Properties

Other Resources

Browser Support

  • (modern) means the recent syntax from the specification (e.g. display: flex;)
  • (hybrid) means an odd unofficial syntax from 2011 (e.g. display: flexbox;)
  • (old) means the old syntax from 2009 (e.g. display: box;)
Chrome Safari Firefox Opera IE Android iOS
21+ (modern)
20- (old)
3.1+ (old) 2-21 (old)
22+ (new)
12.1+ (modern) 10+ (hybrid) 2.1+ (old) 3.2+ (old)

Blackberry browser 10+ supports the new syntax.

For more informations about how to mix syntaxes in order to get the best browser support, please refer to this article (CSS-Tricks) or this article (DevOpera).

icon-link icon-logo-star icon-search icon-star