Course contentsShow
← Web Development
Lesson 295 of 2,9825. FlexboxFree lesson

Equal Height Columns

Create columns that naturally match height regardless of content length.

Equal Height Columns

What you'll learn: How to make all columns in a row automatically match the tallest column's height using Flexbox.

Before Flexbox, creating columns that matched heights required awkward hacks (like fake columns with background images or JavaScript calculations). But with Flexbox, equal-height columns happen automatically—it's one of Flexbox's most powerful features.

The Core Idea

When you set display: flex on a container, all direct children (flex items) stretch to fill the container's cross axis by default. If your flex-direction is row (the default), the cross axis is vertical—meaning all items naturally grow to match the tallest item's height.

Think of it like books on a shelf with adjustable bookends: no matter how thick each book is, the shelf itself is tall enough to fit the tallest book, and the bookends extend to that same height.

How It Works

.container {
  display: flex;
  /* flex-direction: row; — this is the default */
}

.column {
  flex: 1; /* each column takes equal width */
  padding: 1rem;
  background: lightblue;
}
<div class="container">
  <div class="column">Short content</div>
  <div class="column">This column has much more content that makes it taller than the others.</div>
  <div class="column">Medium amount</div>
</div>

All three columns will match the height of the middle one automatically! The default align-items: stretch behavior makes this happen without any extra code.

When You Don't Want Stretching

If you need columns at their natural height, override with align-items: flex-start on the container.

Key Takeaway: Flexbox solves equal-height columns effortlessly—just use display: flex on the parent, and columns stretch to match the tallest one by default.