Subgrid Alignment
CSS Grid changed how we think about page layout, but it came with one stubborn limitation from the start: only the direct children of a grid container participate in its layout. Everything nested deeper is on its own. For many layouts, this is fine. For cards, it creates a problem that looks minor until you actually encounter it in a real project, and then it becomes one of those issues you cannot unsee.
Subgrid is the feature that closes this gap. It allows a grid item to inherit the track definitions of its parent grid rather than inventing its own, letting deeply nested elements lock into a shared rhythm across the entire layout. This reading explains the problem, the mental model behind the solution, and how to apply it.
The Problem Grid Cannot Solve Alone
Imagine a card grid. Each card has three parts: a title, a body paragraph, and a footer button. The cards sit in a three-column parent grid using auto-fit and minmax(). Each card is itself a small grid with three rows, one for each part.
/* Parent grid */
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 1.5rem;
}
/* Each card is its own grid */
.card {
display: grid;
grid-template-rows: auto 1fr auto;
}
On paper, this looks correct. In practice, the three rows inside each card are sized independently from the rows inside every other card. The title row in card one is sized to fit card one's title. The title row in card two is sized to fit card two's title. There is no connection between them. When card titles have different amounts of text, the body paragraphs start at different heights across the row, and the footer buttons end up at different heights too. The grid looks uneven even though no individual card is broken. The demo below shows three cards in one row, each sizing its title row from its own content.
--name syntax. They participate in the cascade and inheritance, making them ideal for design tokens.This is not a bug. It is exactly how CSS Grid is supposed to work. Each card creates an independent formatting context. The only grid that knows about all three columns simultaneously is the parent, and the parent has no visibility into the internal rows of its children. Closing this gap requires a way to share track definitions across the parent/child boundary, which is precisely what subgrid provides.
How Subgrid Inherits Tracks
The key idea is that a grid item can become a subgrid by declaring display: grid on itself and then setting grid-template-rows: subgrid, grid-template-columns: subgrid, or both. When you do this, instead of defining its own track sizes, the element borrows the track definitions from the parent grid for however many tracks it spans.
.card {
/* Span three rows in the parent grid */
grid-row: span 3;
/* Become a grid container */
display: grid;
/* Inherit those three row tracks from the parent */
grid-template-rows: subgrid;
}
The display: grid declaration might seem strange here. You are not creating a new independent grid; you are opting the card's children into grid layout. Without it, the card's children would use normal flow layout and have no awareness of any grid tracks at all. The subgrid keyword then tells CSS to populate those tracks by borrowing the parent's definitions rather than computing new ones from the card's own content.
Because the parent now controls row sizing across all three cards simultaneously, it can find the tallest title among all the cards and give every title row that same height. The same happens for the body row and the footer row. All cards share a single row rhythm, regardless of how much content they individually contain.
What Gets Inherited and What Does Not
Subgrid inherits track sizes and line names from the parent. It does not inherit the parent's gap. You can set a different gap on the subgrid if you want different spacing between the card's internal rows than between the cards themselves. Named grid lines defined on the parent are passed through and remain usable inside the subgrid, which is especially useful when you have named the parent's rows explicitly.
Subgrid works on rows, columns, or both axes independently. In the card alignment pattern, you almost always subgrid only the rows, because each card occupies a single column and has no reason to share column tracks with its siblings.
Seeing It in Action
The demo below shows the same three cards with subgrid enabled by default. Turn the switch off to see each card size its title, body, and footer rows independently; turn it on to let the parent grid control all three row zones simultaneously so the tallest content in each zone sets the height for every card in the row:
--name syntax. They participate in the cascade and inheritance, making them ideal for design tokens.In the "Without Subgrid" view, each card sizes its title row based on its own content alone. The card with the longest title pushes its body down, and the footer buttons sit at different heights. In the "With Subgrid" view, the parent grid takes control of all three row tracks simultaneously, finding the tallest content in each zone and applying that height uniformly across every card in the row.
The CSS That Makes It Work
The parent grid defines three row tracks and the cards span all three. Setting grid-template-rows: subgrid on the card tells it to borrow those tracks rather than size its own:
/* Parent: three-column fluid grid, three shared row tracks */
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
grid-template-rows: auto 1fr auto;
gap: 1.5rem;
align-items: stretch;
}
/* Each card spans all three row tracks */
.card {
grid-row: span 3;
display: grid;
grid-template-rows: subgrid;
gap: 0.75rem;
}
/* Card parts automatically map to the inherited row tracks */
.card-title { /* occupies row track 1 */ }
.card-body { /* occupies row track 2 */ }
.card-footer { /* occupies row track 3 */ }
align-items: stretch Matters
For subgrid row inheritance to work across a row of cards, the cards themselves must stretch to fill the full height of all three tracks. The default align-items: start on the parent would shrink each card to its content height and break the shared rhythm. Setting align-items: stretch on the parent grid ensures every card in the row is the same height before subgrid divides that height into tracks.
The Semantic HTML Bonus
There is a second scenario where subgrid earns its keep, and it connects to a problem you may have already run into: intermediate wrapper elements that break flat grid placement.
Suppose you have a portfolio grid where images should each occupy their own cell. Semantically, those images belong inside a <ul> because they are a list of items. But adding that <ul> wrapper collapses all the images into one grid cell, because the <ul> is the grid participant, not the individual images.
/* The parent: a 4-column grid */
.portfolio-grid {
display: grid;
grid-template-columns: 35% 1fr 1fr 1fr;
}
/* The spans both rows and all three right-hand columns */
.portfolio-grid ul {
grid-row: span 2;
grid-column: span 3;
display: grid;
grid-template-rows: subgrid;
grid-template-columns: subgrid;
}
By setting both grid-template-rows: subgrid and grid-template-columns: subgrid on the <ul>, the list items inherit the parent's column and row tracks. Each <li> now occupies its own cell in the parent grid exactly as if the <ul> wrapper were not there, while the markup stays semantically correct. This is the same problem that display: contents solves, but subgrid does it without removing the wrapper element from the accessibility tree.
If you studied display: contents as a choose topic, notice that subgrid is often the safer alternative. The element remains a real box in the layout, retains its ARIA role, and can still receive its own gap value. display: contents removes the box entirely, which collapses focus indicators and can create accessibility issues on interactive elements.
Browser Support and Practical Fallbacks
As of mid-2026, subgrid sits at roughly 88% global browser support. That is a solid number for a production feature, especially in projects where you control or know your audience. The remaining 12% is primarily older browsers and some mobile environments where the layout will simply degrade to the pre-subgrid behavior: cards that size their rows independently. For most card designs, that is an imperfect but completely readable fallback.
When you need to be explicit, @supports lets you opt into subgrid only where it is available and provide a reasonable default otherwise:
/* Base: each card manages its own rows */
.card {
display: grid;
grid-template-rows: auto 1fr auto;
}
/* Progressive enhancement: share tracks with the parent */
@supports (grid-template-rows: subgrid) {
.card-grid {
grid-template-rows: auto 1fr auto;
align-items: stretch;
}
.card {
grid-row: span 3;
grid-template-rows: subgrid;
}
}
This pattern treats aligned cards as an enhancement rather than a requirement. Browsers that understand subgrid get the polished, synchronized layout. Browsers that do not get readable cards that simply lack the cross-card alignment. Whether this fallback is acceptable depends on the project, but for most content-driven layouts it is perfectly reasonable to ship without a full fallback.
Key Concepts Summary
Subgrid addresses the core limitation of CSS Grid that prevented deeply nested elements from participating in a parent grid's track system. The card alignment problem is the most common real-world use case: multiple cards in a row share internal zones (title, body, footer) that need to align across the row even when their content varies in length. By setting grid-template-rows: subgrid on a grid item that spans multiple parent tracks, the item's children inherit those tracks directly, and the parent grid sizes them all at once.
The feature also provides a semantically safe solution to the wrapper-element problem that otherwise requires flattening HTML or using display: contents. At 88% browser support, it is ready for progressive enhancement today, and the @supports guard makes the fallback straightforward to implement.
Resources
- MDN: Subgrid — Complete reference for syntax, behavior, and browser notes
- Josh W. Comeau: Brand New Layouts with CSS Subgrid — Deep dive with interactive examples covering the fundamentals and more advanced layout possibilities
- Can I Use: CSS Subgrid — Current browser support data
- Kevin Powell: Easy and More Consistent Layouts Using Subgrid — Video walkthrough of the card alignment pattern