Open Playground
CSS FlexboxLesson #178

Flexbox Align Items

The `align-items` property

CSS align-items Property

The align-items property aligns the flex items vertically (on the cross-axis).

This property can have one of the following values:

  • normal (default)
  • stretch
  • center
  • flex-start
  • flex-end
  • baseline

Example

Example Code

css
Try it Yourself
.flex-container {

  display: flex;
  height: 200px;

  align-items: center;
}

Example

Example Code

css
Try it Yourself
.flex-container {

  display: flex;
  height: 200px;

  align-items: flex-start;
}

Example

Example Code

css
Try it Yourself
.flex-container {

  display: flex;
  height: 200px;

  align-items: flex-end;
}

Example

Example Code

css
Try it Yourself
.flex-container {

  display: flex;
  height: 200px;

  align-items: stretch;
}

CSS align-content Property

The align-content property aligns the flex lines. It only has effect when flex items wrap onto multiple lines.

This property can have one of the following values:

  • stretch (default)
  • center
  • flex-start
  • flex-end
  • space-between
  • space-around
  • space-evenly

Example

Example Code

css
Try it Yourself
.flex-container {

  display: flex;
  height: 400px;

  flex-wrap: wrap;

  align-content: center;

}

Example

Example Code

css
Try it Yourself
.flex-container {

  display: flex;
  height: 400px;

  flex-wrap: wrap;

  align-content: space-between;

}

True Centering With Flexbox

The following example shows how to solve a common style problem: true centering.

To achieve true centering, set both the justify-content and the align-items properties to center for the flex container, and the flex item will be perfectly centered both horizontally and vertically:

True Centering

Example

Example Code

css
Try it Yourself
.flex-container {
  display: flex;
  height: 400px;
  justify-content:
  center;
  align-items: center;
}


Interactive Code Examples

CSS Example 1

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview:

CSS Example 2

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview:

CSS Example 3

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview:

CSS Example 4

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview:

CSS Example 5

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview:

CSS Example 6

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview: