Thanks to visit codestin.com
Credit goes to www.cssportal.com

CSS Portal

CSS align-items Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The align-items property plays a central role in how items are positioned along the cross axis inside a flex or grid container. While the main axis is typically controlled by layout flow (such as row or column direction), align-items determines how child elements are aligned perpendicular to that direction. This makes it especially useful for controlling vertical alignment in horizontal layouts, or horizontal alignment in vertical layouts. It applies to all direct children of a container and provides a consistent way to align content without needing individual adjustments on each item.

In practice, align-items is often used to create visually balanced layouts, such as vertically centering text next to an icon or ensuring that cards in a row align neatly regardless of their internal content. Because it affects all items at once, it helps maintain visual harmony and reduces the need for repetitive styling. It also works closely with layout behavior defined by other properties, such as flex-direction, which determines the orientation of the main and cross axes, and align-content, which controls spacing between multiple rows or columns of items when wrapping occurs.

Another important aspect of align-items is how it interacts with individual elements. While it defines a default alignment for all children, this can be overridden on a per-item basis using align-self. This allows for flexible designs where most items follow a shared alignment, but certain elements can break that pattern when needed. Together, these properties make align-items a key part of building responsive, clean, and predictable layouts - especially when combined with thoughtful use of spacing, sizing, and container structure.

Definition

Initial value
stretch
Applies to
All elements
Inherited
No
Computed value
as specified
Animatable
yes
JavaScript syntax
object.style.alignItems

Interactive Demo

One
Two
Three

Syntax

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

Values

  • flex-startElements are located at the beginning of the container line. For layout grid elements (grid elements) the abbreviated start value is allowed, for flex elements it is necessary to use the full flex-start value.
  • flex-endElements are located at the end of the container line. For layout grid elements (grid elements), the abbreviated end value is allowed; for flex elements, the full flex-end value must be used.
  • centerElements are located in the center of the row of the container (middle of the transverse axis, or the axis of the column).
  • baselineElements are located on their baseline.
  • stretchFlex elements are stretched to fit the container along the transverse axis, layout grid elements are stretched along the column. This is the default value.

Example

<div class="wrapper">
<h2>align-items: center</h2>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
</div>
.wrapper {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  padding: 24px;
}

.container {
  display: flex;
  height: 180px;
  border: 2px dashed #e5e7eb;
  background: #f8fafc;
  gap: 16px;
  padding: 16px;
  align-items: center;
  justify-content: center;
}

.item {
  width: 64px;
  height: 64px;
  background: #2563eb;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.12);
}

Browser Support

The following information will show you the current browser support for the CSS align-items property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!