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

Pricing Table Pattern

Create pricing cards with equal heights and bottom-aligned CTAs.

Pricing Table Pattern

What you'll learn: You'll learn how to create professional pricing cards that align perfectly side-by-side with their call-to-action buttons positioned at the bottom, no matter how much content each card contains.

The Problem This Solves

Pricing tables typically show multiple subscription tiers (Free, Pro, Enterprise). Each tier has different features—some have long lists, others have short ones. Without Flexbox, the "Sign Up" buttons end up at different heights, creating a messy, unprofessional look.

How Flexbox Fixes This

The pattern uses nested flex containers:

  1. Outer container (display: flex) makes cards sit side-by-side with equal heights automatically
  2. Inner container (each card is also display: flex with flex-direction: column) stacks content vertically
  3. Auto-margin trick on the button (margin-top: auto) pushes it to the bottom

Think of it like shelves in a bookcase: all shelves are the same height (equal cards), but books of different sizes sit on each shelf. By placing a weight at the bottom of each shelf, you ensure everything aligns perfectly at the base.

The Core Structure

.pricing-table {
  display: flex;
  gap: 2rem;
}

.pricing-card {
  display: flex;
  flex-direction: column;
  flex: 1; /* Equal widths */
  border: 1px solid #ddd;
  padding: 2rem;
}

.pricing-card .btn {
  margin-top: auto; /* Push to bottom */
}

The margin-top: auto on the button consumes all available space, forcing the button downward regardless of how much feature text exists above it.

Key Takeaway: The pricing table pattern uses flex containers inside flex items, with margin-top: auto on the CTA button to ensure bottom alignment across cards of equal height.