---
title: "Why are my grid or flex items stretching to the same height?"
description: "Flex and grid items stretch to fill the cross axis by default because align-items starts as stretch. Learn how to stop it, or use it to build equal-height cards."
url: https://www.danny.engineering/answer/css/why-are-my-grid-or-flex-items-stretching-to-the-same-height
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T18:57:00.000Z
tags: ["CSS"]
---

# Why are my grid or flex items stretching to the same height?

## The short answer


Flexbox and grid stretch their items along the cross axis by default. In a row, that means every item becomes as tall as the tallest one. Set `align-items` on the container, or `align-self` on one item, to something other than stretch.


```css
.row {
  display: flex;
  align-items: flex-start; /* items keep their own height */
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: start;
}
```


## Why it happens


In a flex container, the initial value of `align-items` is `stretch`. Any item whose cross size is `auto` (its height, in a row) grows to fill the line. The line is as tall as its tallest item, so every item matches it.


Grid works the same way inside each grid area. The initial value is `normal`, which behaves as `stretch` for most items. Each row is as tall as its tallest item, and every item in the row stretches to fill its cell. Items with an intrinsic aspect ratio, such as images, are the exception in grid: they keep their ratio instead of stretching.


This default is deliberate. It is the reason equal-height columns, which used to need table hacks, take one line of flexbox. It only becomes a problem when you did not want it: a short button next to tall text, a sidebar that fills the whole page height, or an image stretched out of shape in a flex row.


## How to fix it


### Change align-items on the container


Pick the alignment you want for all items.


```css
.toolbar {
  display: flex;
  align-items: center; /* centre each item vertically */
}
```


In flexbox, use `flex-start`, `center`, `flex-end` or `baseline`. In grid, use `start`, `center`, `end` or `baseline`. Modern browsers also accept `start` and `end` in flexbox.


### Override one item with align-self


If most items should stretch but one should not, set `align-self` on that item.


```css
.media {
  display: flex;
  gap: 1rem;
}

.media img {
  align-self: flex-start; /* keep the image's natural height */
}
```


### Give the item an explicit height


Stretch only affects items with an `auto` cross size. Setting `height` (or `width` in a column layout) on an item stops it stretching. This is useful when the size is fixed by design, but alignment properties are usually cleaner.


### Use the stretch on purpose for card layouts


When you do want equal heights, keep the default and make each card a flex column, so its footer sits at the bottom whatever the content length.


```css
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 1.5rem;
}

.card {
  display: flex;
  flex-direction: column;
}

.card__footer {
  margin-top: auto; /* pushes the footer down */
}
```


## Common pitfalls

- Looking at the item for the cause. The stretching comes from the container's `align-items`, so inspect the parent.
- Mixing up axes. In a column flex layout, the cross axis is horizontal, so items stretch to full width, not height. `justify-content` controls the main axis; `align-items` controls the cross axis.
- Wrapped flex rows. With `flex-wrap: wrap`, each line stretches its items to that line's height only, so different rows can have different heights.
- Images in a flex row. An `img` with `auto` height is stretched to the row height and distorted. Use `align-self: flex-start` or `object-fit: cover`.
- A page-level sidebar that fills the full height of a long main column. That is stretch working as intended; set `align-self: start` and, if needed, `position: sticky`.

## Related reading

- [MDN: align-items](https://developer.mozilla.org/en-US/docs/Web/CSS/align-items)
- [MDN: Aligning items in a flex container](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_flexible_box_layout/Aligning_items_in_a_flex_container)
