Mastering CSS Grid Layouts (Part 3): Subgrid for Real Component Alignment
Use CSS subgrid to align nested cards, forms and content with parent tracks. Learn column and row subgrids, gaps, named lines, fallbacks and when an independent nested grid is still better.

One of CSS Grid’s original limitations was surprisingly awkward: nested grids did not know anything about the tracks above them.
You could create a beautiful three-column parent grid, place three cards inside it, then make each card a grid — but those inner grids were independent. A long title in one card could push its button lower while the other cards used different row heights. Form labels in neighboring components almost lined up, but not quite. Developers compensated with fixed heights, JavaScript measurements and duplicated track definitions.
subgrid fixes that class of problem.
Instead of a nested grid inventing its own tracks, it can adopt the tracks of the parent grid in one axis, the other axis, or both.
As of 2026, subgrid is a well-established cross-browser feature, so it can be treated as a normal layout tool rather than an experimental curiosity.
The problem subgrid solves
Start with three cards:
<div class="cards">
<article class="card">
<h2>Short title</h2>
<p>Some copy.</p>
<a href="#">Read more</a>
</article>
<article class="card">
<h2>A much longer title that wraps onto two lines</h2>
<p>Some copy.</p>
<a href="#">Read more</a>
</article>
<article class="card">
<h2>Another title</h2>
<p>Some copy that is longer than the others.</p>
<a href="#">Read more</a>
</article>
</div>
A common first attempt is:
.cards {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1rem;
}
.card {
display: grid;
grid-template-rows: auto 1fr auto;
}
Each card has the same idea of three rows, but each card calculates those rows independently.
That means the title row in card one can have a different height from the title row in card two.
If you want headings, body copy and buttons to align across all cards, a normal nested grid cannot share row sizing with its siblings.
That is exactly where subgrid helps.
A row subgrid for aligned cards
First, make the parent define the rows the cards will participate in.
.cards {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 1rem;
}
.card {
display: grid;
grid-template-rows: subgrid;
grid-row: span 3;
}
Each card spans three parent row tracks and adopts those tracks through subgrid.
Conceptually:
Parent grid rows
row 1 ───────────────── headings
row 2 ───────────────── content
row 3 ───────────────── actions
Card A uses those rows
Card B uses those rows
Card C uses those rows
The tallest heading determines the shared first-row size. The longest body content affects the shared second row. Buttons line up on the third.
No fixed heights required.
Why grid-row: span 3 is needed
A subgrid adopts the part of the parent grid that the child itself spans.
If the card only occupies one parent row, there is only one row track available to subgrid.
By saying:
.card {
grid-row: span 3;
grid-template-rows: subgrid;
}
you give the card three parent row tracks to inherit.
That relationship is central to understanding subgrid:
A subgrid does not magically expose the parent’s entire grid. It inherits the tracks across the portion of the parent that the subgrid item spans.
Column subgrid works the same way
Imagine a form layout where several field groups should share label and input columns.
Parent:
.form {
display: grid;
grid-template-columns: max-content minmax(0, 1fr);
gap: 1rem 1.5rem;
}
Each field group might contain its own label and control:
<div class="field">
<label for="name">Name</label>
<input id="name">
</div>
Without subgrid, .field creating its own two-column grid would size those columns independently.
With subgrid:
.field {
display: grid;
grid-template-columns: subgrid;
grid-column: 1 / -1;
}
Each field adopts the parent’s two columns.
Now labels align across groups even though the markup is componentized.
Subgrid can work in one axis only
This is often the sweet spot.
A card may need to align rows with sibling cards while still defining its own columns:
.card {
display: grid;
grid-template-rows: subgrid;
grid-template-columns: auto minmax(0, 1fr);
}
Or a component may inherit columns from the page shell while managing rows independently:
.section {
display: grid;
grid-template-columns: subgrid;
grid-auto-rows: auto;
}
You do not have to make the component a subgrid in both dimensions.
Choose the axis where cross-component alignment actually matters.
Subgrid in both axes
You can inherit both rows and columns:
.child {
display: grid;
grid-template-columns: subgrid;
grid-template-rows: subgrid;
}
That can be useful for complex nested layout regions, but it also tightly couples the child to the parent’s track structure.
Use it when that alignment relationship is intentional.
A component that should remain portable across unrelated page layouts may be better off subgridding only one axis or using its own independent grid.
Subgrid preserves parent track sizing
The important distinction between a nested grid and a subgrid is who owns the track sizes.
Independent nested grid:
.parent {
grid-template-columns: 12rem 1fr;
}
.child {
display: grid;
grid-template-columns: 12rem 1fr;
}
This looks aligned because you duplicated the values.
But the two grids are still separate. Change one and you can accidentally break the relationship.
Subgrid:
.parent {
grid-template-columns: 12rem minmax(0, 1fr);
}
.child {
display: grid;
grid-template-columns: subgrid;
grid-column: 1 / -1;
}
Now there is one source of truth for the columns.
That makes subgrid particularly valuable in design systems where layout primitives should control alignment across nested components.
Gaps are inherited — but can be overridden
A subgrid normally inherits the parent’s gap behaviour in the subgridded axis.
For example:
.parent {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 2rem;
}
.child {
display: grid;
grid-template-columns: subgrid;
grid-column: 1 / -1;
}
The subgrid aligns with the parent’s track spacing.
But the child can override its own gap:
.child {
grid-template-columns: subgrid;
column-gap: 1rem;
}
That capability is useful, but be careful: changing the apparent spacing while sharing the same track boundaries can make the layout visually harder to reason about.
Use overrides because the component design calls for them, not merely because you can.
Named lines can flow into a subgrid
Named grid lines make subgrid even more expressive.
Parent:
.page {
display: grid;
grid-template-columns:
[full-start] minmax(1rem, 1fr)
[content-start] minmax(0, 70rem)
[content-end] minmax(1rem, 1fr)
[full-end];
}
A child spanning those tracks can subgrid the columns:
.section {
display: grid;
grid-column: full-start / full-end;
grid-template-columns: subgrid;
}
Descendants can then align to inherited named lines:
.section__content {
grid-column: content-start / content-end;
}
This creates a powerful pattern: page-level alignment names can remain available inside nested sections without duplicating the entire column definition.
Subgrids can add line names too
A subgrid may introduce additional names for inherited lines.
That lets a component speak both the parent’s layout language and its own.
For example, the parent may expose content-start, while the component adds an internal semantic alias such as label-start for a line it uses frequently.
This is useful in sophisticated design systems, but keep the naming disciplined. If every component introduces five aliases for the same boundary, the layout becomes harder rather than easier to understand.
A practical pricing-card pattern
Suppose pricing cards need aligned feature lists and call-to-action buttons.
<div class="pricing">
<article class="plan">
<h2>Starter</h2>
<p class="price">£9</p>
<ul>...</ul>
<a class="button" href="#">Choose Starter</a>
</article>
<article class="plan">
<h2>Professional</h2>
<p class="price">£29</p>
<ul>...</ul>
<a class="button" href="#">Choose Professional</a>
</article>
</div>
Use four shared rows:
.pricing {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
gap: 1.5rem;
}
.plan {
display: grid;
grid-template-rows: subgrid;
grid-row: span 4;
}
Now each plan’s:
- heading;
- price;
- feature list;
- button
shares row sizing with the corresponding content in sibling cards.
A longer feature list expands the shared feature row without pushing its button out of alignment.
This is exactly the kind of UI developers previously solved with height: 7rem or JavaScript equal-height scripts.
Form groups are another natural fit
Consider a settings page made from reusable field components:
<form class="settings">
<div class="setting-row">
<label>Email reports</label>
<div class="control">...</div>
<p class="help">Send a weekly summary.</p>
</div>
<div class="setting-row">
<label>Timezone</label>
<div class="control">...</div>
<p class="help">Used for report delivery.</p>
</div>
</form>
Parent tracks:
.settings {
display: grid;
grid-template-columns:
minmax(10rem, max-content)
minmax(12rem, 1fr)
minmax(12rem, 24rem);
gap: 1rem 2rem;
}
Each row:
.setting-row {
display: grid;
grid-template-columns: subgrid;
grid-column: 1 / -1;
}
The componentized rows align perfectly because they all inherit the same columns.
At a narrow breakpoint, the parent can change its columns and the subgrids follow automatically.
Responsive subgrid is especially useful
Desktop:
.settings {
grid-template-columns: 12rem minmax(0, 1fr) 20rem;
}
Mobile:
@media (max-width: 48rem) {
.settings {
grid-template-columns: minmax(0, 1fr);
}
}
The child can remain:
.setting-row {
grid-template-columns: subgrid;
grid-column: 1 / -1;
}
The parent’s layout decision propagates down.
That is substantially easier to maintain than redefining matching child column templates at each breakpoint.
Subgrid is not the same thing as display: contents
Before widespread subgrid support, developers sometimes used:
.child {
display: contents;
}
to effectively remove a wrapper’s box so its children could participate directly in the ancestor grid.
That can occasionally be useful, but it changes the box tree and has historically carried accessibility and styling caveats depending on browser behaviour and element semantics.
Subgrid solves a different problem more directly: the wrapper remains a real grid item and real box, while its internal grid adopts parent tracks.
Do not use display: contents as a substitute for subgrid merely because an old article recommended it.
When subgrid is the wrong tool
Subgrid is useful when alignment across the parent-child boundary matters.
Do not use it automatically for every nested grid.
An independent grid is often better when:
- the component should be portable between unrelated containers;
- its internal layout has no meaningful relationship to parent tracks;
- the child needs track sizing that differs from the parent;
- coupling to the parent’s number of tracks would make the component fragile;
- the component’s responsive behaviour should be self-contained.
For example, a reusable date picker inside a dashboard should probably define its own calendar grid. There is no value in forcing its seven weekday columns to align with the dashboard’s outer columns.
Think of subgrid as inherited geometry
Normal inheritance passes property values such as color and font down the DOM tree.
Subgrid is not ordinary CSS inheritance, but conceptually it is useful to think of it as inheriting layout geometry.
The parent says:
These are the tracks.
The subgrid says:
For the region I occupy, use those same tracks inside me.
That is why subgrid is so powerful for systems that value alignment.
Common subgrid mistakes
Forgetting to span enough parent tracks
If a row subgrid needs three rows, the subgrid item needs to span three parent rows.
Using subgrid when the child should be independent
Shared geometry is coupling. Make sure it is useful coupling.
Duplicating parent track definitions anyway
If you write subgrid and then try to recreate independent track sizes in the same axis, you are fighting the feature.
Expecting subgrid to include tracks outside the child’s span
The child only inherits the portion of the parent it occupies.
Ignoring source order
Subgrid does not change accessibility principles. Keep document order logical even when layout becomes more sophisticated.
Building fixed-height cards before trying row subgrid
If the purpose of the fixed heights is alignment between repeated components, subgrid may remove the need entirely.
Good component layout should survive real content
Once the page is deployed, SiteTidy can help inspect the wider technical quality while you verify the layout itself across content lengths and viewports.
Progressive enhancement and support
Subgrid has been widely available across modern browsers since 2023, which changes the practical decision substantially compared with older tutorials.
For modern application support matrices, you can generally use it directly after checking the browser versions your own users require.
If you genuinely support older browsers without subgrid, decide what the fallback needs to achieve.
It may be acceptable for cards simply not to align perfectly:
.plan {
display: grid;
grid-template-rows: auto 1fr auto;
}
@supports (grid-template-rows: subgrid) {
.plan {
grid-template-rows: subgrid;
grid-row: span 3;
}
}
The fallback does not always need to reproduce pixel-identical geometry. It needs to remain usable.
A design-system pattern worth keeping
A powerful page primitive is:
.page-grid {
display: grid;
grid-template-columns:
[full-start] minmax(1rem, 1fr)
[content-start] minmax(0, 72rem)
[content-end] minmax(1rem, 1fr)
[full-end];
}
.section {
display: grid;
grid-column: full-start / full-end;
grid-template-columns: subgrid;
}
.section__inner {
grid-column: content-start / content-end;
}
Now every section can participate in the page’s shared alignment system while still remaining its own component and box.
That is the kind of problem subgrid solves elegantly.
Subgrid removes duplicated geometry
The biggest benefit of subgrid is not fewer characters of CSS.
It is removing a category of synchronization problem.
Without subgrid, a parent and child can both claim to use the same columns while quietly drifting apart. With subgrid, there is one track definition and multiple components participating in it.
That improves responsive behaviour, makes content-driven sizing more natural and reduces the temptation to force alignment with fixed heights.
Use subgrid when nested components should genuinely share geometry with their parent. Keep independent grids independent when they should not.
In Part 4, we move into responsive Grid architecture: container queries, auto-fit patterns, fluid tracks, layout breakpoints and how to build components that respond to the space they actually receive rather than the width of the user’s entire screen.
