Skip to content
React & Tailwind

Aligning cards with CSS subgrid

Why titles, prices and buttons in a row of cards do not line up, how subgrid passes the rows of the outer grid on to every card, how many rows a card needs, what it looks like in Tailwind and why display: contents is no shortcut.

8 min readBy Leonie RoesmannUpdated: 23 November 2026
CSSGridLayoutTailwind

Three pricing cards side by side, and in the middle one the title wraps onto two lines. From then on its price sits lower than the others, the list below starts somewhere else, and at the end the buttons sit at three different heights. Every card is a layout of its own and knows nothing about its neighbours. subgrid changes exactly that: a card takes over the rows of the grid it sits in, and so all cards in a row share the same row heights. Chrome and Edge have supported it since version 117, Firefox since version 71, Safari since version 16. This guide shows the problem, the two lines of CSS that solve it, how to set the number of rows, the route in Tailwind and why display: contents is the weaker choice despite a similar result.

The short version
  • subgrid belongs on the card, not on the outer grid. The card gets display: grid, grid-template-rows: subgrid and spans as many rows of the outer grid as it has children with grid-row: span 4.
  • After that every row follows the tallest content in the whole row of cards. A title on two lines pushes price, list and button down by the same amount in every card.
  • The gap is inherited and can be overridden. gap on the outer grid also applies inside the cards; row-gap on the card sets a value of its own there.
  • According to MDN, subgrid has been available in all major browsers since September 2023 and is now Baseline Widely available. Without support the card stays an ordinary grid, just not aligned with its neighbours.
01

Why do buttons and prices in a row of cards not line up?

Because every card has its own layout and does not know the heights of its neighbours. The outer grid makes all cards in a row equally tall. What happens inside the card is the card's own business. If the title wraps in one of them, everything below it moves down by a line there.

The usual fix is a flex column with margin-top: auto on the button. That puts the buttons on one line at the bottom, but only them. Price and list still sit at different heights, and that is exactly where someone choosing between three plans compares.

Fixed heights for the title do not help for long either. They fit the text that is there today and break as soon as a plan is renamed, the font size is turned up or the page is translated.

.plans {  display: grid;  grid-template-columns: repeat(3, 1fr);  gap: 24px;} .plan {  display: flex;  flex-direction: column;} .plan .cta {   margin-top: auto;}
The button sits at the bottom, but price and list follow the length of the title in each card separately.
02

What does subgrid do, and where do you write it?

subgrid passes the rows of the outer grid on to the card, and you write it on the card. The card gets display: grid and grid-template-rows: subgrid and spans four rows of the outer grid with grid-row: span 4. Inside it then has exactly those four rows instead of creating its own.

From then on the outer grid decides the height of every row, and it follows the tallest content in that row across all cards. If the title wraps in one card, the first row gets taller in all three. Price, list and button then start at the same height everywhere.

The outer grid needs no row definition for this. It creates the rows itself as soon as the cards span them, and when the cards wrap onto a second line, simply four more. According to MDN, line numbering starts again at 1 inside the subgrid, so a card does not need to know which row it is in.

.plans {  display: grid;  grid-template-columns: repeat(3, 1fr);  gap: 24px;} .plan {  display: grid;   grid-row: span 4;   grid-template-rows: subgrid;}
Two lines on the card. Title, price, list and button now line up across the row.

The grid does not align the cards. The cards borrow the grid's rows.

03

How many rows does a card with subgrid have to span?

As many as it has children that should sit on lines of their own. Title, price, list and button are four, so grid-row: span 4. The number is fixed, because according to MDN a subgrid creates no additional rows in the direction it takes over.

If a card has more children than rows, for instance because a note is added below the price, it no longer fits the scheme. Either span grows with it, equally in every card, or note and price go into a shared element that takes up one row together.

  1. Gap gap on the outer grid is inherited and also applies between title, price and list. row-gap on the card overrides it there without changing the gap between rows of cards.
  2. Padding The card keeps its box. padding, border and background work as usual, and the rows sit inside the padding.
  3. Line names Named lines of the outer grid arrive in the subgrid, and the subgrid may add its own, for instance grid-template-rows: subgrid [title] [price] [list] [cta].
  4. Both directions subgrid also exists for grid-template-columns. For cards side by side the rows are usually enough; for forms with label and field it is the columns.
One child too manyIf a fifth element appears in a single card, such as a badge above the title, everything there shifts and the alignment is gone. So put optional parts inside an element that every card has, empty if need be.
04

How do you write subgrid in Tailwind?

With grid-rows-subgrid and row-span on the card. grid-rows-subgrid produces grid-template-rows: subgrid, and row-span-4 produces grid-row: span 4 / span 4. For columns there is grid-cols-subgrid. Tailwind introduced these classes in version 3.4 of 19 December 2023, and the documentation for Tailwind 4.3 lists them unchanged.

The outer grid stays as it is: grid and the columns, one on the phone, three from md upwards. On narrow screens the cards stack, each takes four rows for itself, and alignment no longer matters. From md upwards three cards share the same four rows.

export function Plans({ plans }: { plans: Plan[] }) {  return (    <div className="grid gap-6 md:grid-cols-3">      {plans.map((plan) => (        <article          key={plan.id}           className="row-span-4 grid grid-rows-subgrid gap-y-4 rounded-xl border p-6"        >          <h3 className="text-lg font-medium">{plan.name}</h3>          <p className="text-3xl">{plan.price}</p>          <ul className="space-y-2 text-sm">{plan.features}</ul>          <a href={plan.href} className="self-end">Choose plan</a>        </article>      ))}    </div>  );}
A pricing card with four rows. The gap inside is smaller than the one between cards.
Keeping the button at the bottomThe last row is as tall as the tallest button, the list before it as tall as the longest list. That puts the buttons on one line without margin-top: auto. You only need self-end on the button when a row grows taller than its content.
05

Why not simply use display: contents instead of subgrid?

Because display: contents removes the card itself. The element no longer generates a box, its children become direct parts of the outer grid and therefore line up too. But the card's background, border, padding and shadow disappear with it, because nothing is left to carry them.

The second reason is accessibility. Rachel Andrew wrote in March 2021 that display: contents had removed elements from the accessibility tree in all browsers, and that Chrome and Firefox had since fixed this. Eric Bailey showed in May 2023 that the problem could still occur with buttons, headings and tables. For a card with a heading and a button that is not a good trade.

display: contents
  • The card has no box any more; background and border are gone.
  • Every child has to paint its own background to look like a card.
  • Assistive technology no longer announces some elements correctly.
grid-template-rows: subgrid
  • The card stays a box with border, background and padding.
  • The children still line up with the rows of the outer grid.
  • The element keeps its meaning; nothing changes in the markup.
06

Which browsers support subgrid, and do you need a fallback?

Firefox since version 71, Safari since version 16, on the iPhone too, Chrome and Edge since version 117. web.dev gives 15 September 2023 as the date from which subgrid ran in all three engines, and MDN now lists it as Baseline Widely available. Using StatCounter data for October 2026, caniuse puts it at 94.68 percent of page views worldwide.

You usually do not need a fallback of your own. A browser without subgrid drops only that one value. The card stays a grid, still spans four rows and stacks its contents, just with heights of its own. The result is the state from before, not a broken layout.

If you want at least the buttons at the bottom in old browsers, put the flex column with margin-top: auto in a block with @supports not. Browsers with subgrid skip it.

 @supports not (grid-template-rows: subgrid) {  .plan {    display: flex;    flex-direction: column;  }  .plan .cta {    margin-top: auto;  }}
Only active when the browser does not know subgrid.

With subgrid everything lines up. Without it, everything stays as before. Nothing gets worse.

Share
Written by
Leonie RoesmannDesign engineering

We build websites and web apps at Systra Studios in Münster and put the building blocks from that work here. What you read comes from real projects, not from a brochure.

Systra Studios: web design from Münster

A new guide every Monday.

Plus one free section with a preview. One email a week, unsubscribe with one click.

You will get a confirmation email. Unsubscribe with one click. Privacy

Three plans, one line.
The pricing cards for it are ready to take.

Pricing sections with cards side by side: three courses over dark water, two rituals with a toggle, three plans with a highlighted middle. Copy them and line up the rows inside the cards with grid-rows-subgrid.

  • One file per component, as source code in your own project.
  • Built with React, TypeScript and Tailwind CSS v4.
  • All three respect reduced motion.
Browse pricing sections
FAQ

Frequently asked questions

Didn't find your question? Write to us, we answer ourselves.

Get in touch

subgrid is a value for grid-template-rows and grid-template-columns. An element that sits in a grid itself and gets display: grid then creates no rows or columns of its own but takes over those of the surrounding grid, precisely the ones it spans. If a card spans four rows with grid-row: span 4, it has four rows inside whose height the outer grid decides. Because all cards in a row use the same outer rows, their contents line up with each other: titles, prices and buttons sit on one line even if one title is longer than the others. Line numbering starts again at 1 inside the subgrid.

Firefox since version 71, Safari since version 16 on the Mac and on the iPhone, Chrome and Edge since version 117. That means subgrid had arrived in all three browser engines by September 2023; web.dev gives 15 September 2023 as the date for Baseline Newly available. MDN now lists subgrid as Baseline Widely available. Using StatCounter usage data for October 2026, caniuse puts it at 94.68 percent of page views worldwide. Older browsers drop the value subgrid, and the card then stays an ordinary grid with rows of its own.

With the classes grid-rows-subgrid and grid-cols-subgrid, which produce grid-template-rows: subgrid and grid-template-columns: subgrid. Tailwind introduced them in version 3.4 of 19 December 2023, and they are unchanged in Tailwind 4. Add row-span with the number of rows the card should span: row-span-4 produces grid-row: span 4 / span 4. A card with title, price, list and button therefore gets grid row-span-4 grid-rows-subgrid, and the outer grid gets grid and its columns, for instance md:grid-cols-3. The gap inside the card is set by gap-y on the card, the gap between cards by gap on the outer grid.

Visually it gets you a similar distance, but you lose the card. display: contents removes the element's box, and its children become direct parts of the outer grid. The card's background, border, padding and shadow disappear with it, because there is no box left to carry them. Then there is accessibility: in May 2023 Eric Bailey described how display: contents can stop assistive technology from announcing some elements correctly, such as buttons as buttons or tables as tables. subgrid keeps the box and the meaning of the element, which is why it is the better choice for cards.