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.
- 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.
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;}
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;}
The grid does not align the cards. The cards borrow the grid's rows.
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.
- 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.
- Padding The card keeps its box. padding, border and background work as usual, and the rows sit inside the padding.
- 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].
- 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.
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> );}
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.
- 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.
- 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.
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; }}
With subgrid everything lines up. Without it, everything stays as before. Nothing gets worse.






