Skip to content

CSS align-items Property

The CSS align-items property specifies the default alignment for flex items. It is similar to the justify-content property, but aligns items along the cross axis (typically vertical, depending on flex-direction).

Note: This property only applies to flex and grid containers.

This property is one of the CSS3 properties.

The align-items property accepts the following values:

  • stretch
  • flex-start
  • center
  • flex-end
  • baseline
Initial Valuestretch
Applies toFlex and grid containers.
InheritedNo.
AnimatableNo.
VersionCSS3
DOM Syntaxobject.style.alignItems = "center";

Syntax

Syntax of CSS align-items Property

css
align-items: stretch | center | flex-start | flex-end | baseline | initial | inherit;

Example of the align-items property:

Example of CSS align-items Property with stretch value

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      #example {
        width: 220px;
        height: 300px;
        padding: 0;
        border: 1px solid #000;
        display: flex;
        align-items: stretch;
      }
      #example li {
        flex: 1;
        list-style: none;
      }
    </style>
  </head>
  <body>
    <h2>Align-items: stretch; example</h2>
    <ul id="example">
      <li style="background-color:#8ebf42;">Green</li>
      <li style="background-color:#1c87c9;">Blue</li>
      <li style="background-color:#ccc;">Gray</li>
    </ul>
  </body>
</html>

Result

CSS align-items Property with the stretch value

In the following example, the items are positioned at the center of the container.

Example of the align-items property with the "center" value:

Example of CSS align-items Property with center value

html
<!DOCTYPE html>
<html>
  <head>
    <title>The title of the document</title>
    <style>
      #example {
        width: 220px;
        height: 300px;
        padding: 0;
        border: 1px solid #000;
        display: flex;
        align-items: center;
      }
      #example li {
        flex: 1;
        list-style: none;
      }
    </style>
  </head>
  <body>
    <h2>Align-items: center; example</h2>
    <ul id="example">
      <li style="background-color:#8ebf42;">Green</li>
      <li style="background-color:#1c87c9;">Blue</li>
      <li style="background-color:#ccc;">Gray</li>
    </ul>
  </body>
</html>

In the next example, the items are placed at the beginning.

Example of the align-items property with the "flex-start" value:

Example of CSS align-items Property with flex-start value

html
<!DOCTYPE html>
<html>
  <head>
    <title>The title of the document</title>
    <style>
      #example {
        width: 220px;
        height: 300px;
        padding: 0;
        border: 1px solid #000;
        display: flex;
        align-items: flex-start;
      }
      #example li {
        flex: 1;
        list-style: none;
      }
    </style>
  </head>
  <body>
    <h2>Align-items: flex-start; example</h2>
    <ul id="example">
      <li style="background-color:#8ebf42;">Green</li>
      <li style="background-color:#1c87c9;">Blue</li>
      <li style="background-color:#ccc;">Gray</li>
    </ul>
  </body>
</html>

Here, we apply the "flex-end" value which places the items at the end of the container.

Example of the align-items property with the "flex-end" value:

Example of CSS align-items Property with flex-end value

html
<!DOCTYPE html>
<html>
  <head>
    <title>The title of the document</title>
    <style>
      #example {
        width: 220px;
        height: 300px;
        padding: 0;
        border: 1px solid #000;
        display: flex;
        align-items: flex-end;
      }
      #example li {
        flex: 1;
        list-style: none;
      }
    </style>
  </head>
  <body>
    <h2>Align-items: flex-end; example</h2>
    <ul id="example">
      <li style="background-color:#8ebf42;">Green</li>
      <li style="background-color:#1c87c9;">Blue</li>
      <li style="background-color:#ccc;">Gray</li>
    </ul>
  </body>
</html>

Let’s see our last example with the "baseline" value which places the items at the baseline of the container.

Example of the align-items property with the "baseline" value:

Example of CSS align-items Property with baseline value

html
<!DOCTYPE html>
<html>
  <head>
    <title>The title of the document</title>
    <style>
      #example {
        width: 220px;
        height: 300px;
        padding: 0;
        border: 1px solid #000;
        display: flex;
        align-items: baseline;
      }
      #example li {
        flex: 1;
        list-style: none;
      }
    </style>
  </head>
  <body>
    <h2>Align-items: baseline; example</h2>
    <ul id="example">
      <li style="background-color:#8ebf42;">Green</li>
      <li style="background-color:#1c87c9;">Blue</li>
      <li style="background-color:#ccc;">Gray</li>
    </ul>
  </body>
</html>

Result

CSS align-items Property with the baseline value

Values

ValueDescriptionPlay it
stretchMakes items stretch to fit the container. This is the default value for this property.Play it »
centerItems are placed at the center of the container.Play it »
flex-startItems are placed at the beginning of the container.Play it »
flex-endItems are placed at the end of the container.Play it »
baselineItems are positioned at the baseline of the container.Play it »
initialIt makes the property use its default value.Play it »
inheritIt inherits the property from its parents element.

Practice

What are the possible values for the 'align-items' property in CSS?

Dual-run preview — compare with live Symfony routes.