Flexbox & Grid

Align Items

Utilities for controlling how flex and grid items are positioned along a container’s cross axis.

Quick reference

Class
Properties
items-startalign-items: flex-start;
items-endalign-items: flex-end;
items-centeralign-items: center;
items-baselinealign-items: baseline;
items-stretchalign-items: stretch;

Basic usage

Stretch

Use items-stretch to stretch items to fill the container’s cross axis:

Align Items - 图1

  1. <div class="flex items-stretch ...">
  2. <div class="py-4">01</div>
  3. <div class="py-12">02</div>
  4. <div class="py-8">03</div>
  5. </div>

Start

Use items-start to align items to the start of the container’s cross axis:

Align Items - 图2

  1. <div class="flex items-start ...">
  2. <div class="py-4">01</div>
  3. <div class="py-12">02</div>
  4. <div class="py-8">03</div>
  5. </div>

Center

Use items-center to align items along the center of the container’s cross axis:

Align Items - 图3

  1. <div class="flex items-center ...">
  2. <div class="py-4">01</div>
  3. <div class="py-12">02</div>
  4. <div class="py-8">03</div>
  5. </div>

End

Use items-end to align items to the end of the container’s cross axis:

Align Items - 图4

  1. <div class="flex items-end ...">
  2. <div class="py-4">01</div>
  3. <div class="py-12">02</div>
  4. <div class="py-8">03</div>
  5. </div>

Baseline

Use items-baseline to align items along the container’s cross axis such that all of their baselines align:

Align Items - 图5

  1. <div class="flex items-baseline ...">
  2. <div class="pt-2 pb-6">01</div>
  3. <div class="pt-8 pb-12">02</div>
  4. <div class="pt-12 pb-4">03</div>
  5. </div>

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:items-center to only apply the items-center utility on hover.

  1. <div class="flex items-stretch hover:items-center">
  2. <!-- ... -->
  3. </div>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:items-center to apply the items-center utility at only medium screen sizes and above.

  1. <div class="flex items-stretch md:items-center">
  2. <!-- ... -->
  3. </div>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.