align-items

34 Cross on Updated on
##description##
Ad
`, } ); } })();

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

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

Syntax

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

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:

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:

Browser support

Browser support for align-items varies in its usage with flexbox and CSS Grid.

Flex layout

Grid layout

More information