Layout systems
Practical CSS Subgrid: Aligning Card Headers and Footers Across Uneven Rows
Solve the card alignment problem once and for all with CSS subgrid. How grid-template-rows: subgrid aligns button footers regardless of paragraph length.
BLUF (Bottom Line Up Front)
When building responsive card grids, variable content length (such as a 3-line card title next to a 1-line title) routinely misaligns card footers and action buttons. Historically solved with rigid fixed heights or JavaScript resize observers, CSS Subgrid (grid-template-rows: subgrid) allows child card elements to participate directly in the parent grid’s row sizing tracks, guaranteeing pixel-perfect alignment across cards.
1. The Classic Card Misalignment Problem
Consider a standard 3-column pricing or feature grid:
- Card 1 has a 1-line title and a 2-line description.
- Card 2 has a 3-line title and a 5-line description.
In standard CSS Grid or Flexbox, each card is an independent formatting context. The ‘Sign Up’ buttons at the bottom end up at different vertical offsets, creating a jagged, unpolished visual appearance.
2. How CSS Subgrid Solves Row Track Inheritance
With CSS Subgrid, child cards span multiple parent rows and inherit the row tracks:
/* Parent Grid */
.pricing-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1.5rem;
}
/* Child Card using Subgrid */
.pricing-card {
display: grid;
grid-row: span 3; /* Spans Header, Body, Footer */
grid-template-rows: subgrid;
}
+-------------------------------------------------------------+
| Subgrid Row Track Alignment |
+-------------------------------------------------------------+
| Track 1 (Header): | Card 1 Header | Card 2 Tall Header |
| | | (Rows match max height)|
|-------------------+----------------+------------------------|
| Track 2 (Body): | Card 1 Body | Card 2 Body |
|-------------------+----------------+------------------------|
| Track 3 (Footer): | [ Button ] | [ Button ] |
| | (Buttons align perfectly on same baseline)
+-------------------------------------------------------------+
3. Tailwind CSS Subgrid Implementation
Tailwind CSS natively supports subgrid utilities:
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<!-- Pricing Card 1 -->
<div class="grid grid-rows-subgrid row-span-3 rounded-2xl border border-slate-200 bg-white p-6 shadow-sm">
<h3 class="text-xl font-bold text-slate-900">Starter Plan</h3>
<p class="text-sm text-slate-600">Essential cloud tooling for early prototypes.</p>
<button class="mt-4 w-full rounded-xl bg-slate-900 py-2.5 text-white font-semibold">Get Started</button>
</div>
<!-- Pricing Card 2 (With Long Header) -->
<div class="grid grid-rows-subgrid row-span-3 rounded-2xl border border-indigo-200 bg-indigo-50/30 p-6 shadow-sm">
<h3 class="text-xl font-bold text-slate-900">Enterprise High-Throughput Cluster Tier</h3>
<p class="text-sm text-slate-600">Full telemetry, 99.99% SLA, and dedicated engineering support.</p>
<button class="mt-4 w-full rounded-xl bg-indigo-600 py-2.5 text-white font-semibold">Contact Sales</button>
</div>
</div>
4. Browser Support and Progressive Enhancement
As of 2026, CSS Subgrid is supported across all major browsers (Chrome 117+, Safari 16+, Firefox 71+, Edge 117+).
For legacy browser resilience, provide a simple flexbox fallback using @supports:
.card {
display: flex;
flex-direction: column;
justify-content: space-between;
}
@supports (grid-template-rows: subgrid) {
.card {
display: grid;
grid-row: span 3;
grid-template-rows: subgrid;
}
}
Frequently Asked Questions
Can Subgrid be applied to columns as well as rows?
Yes. You can declare grid-template-columns: subgrid; to inherit parent column coordinates (useful for nested multi-column forms).
Does Subgrid impact layout rendering performance?
No. Because subgrid track resolution occurs during standard grid tree compilation, performance is indistinguishable from standard CSS Grid.
Sources
Frequently asked questions
- How can developers test this design technique?
- Open browser developer tools, enable the CSS Grid overlay, and inspect track sizes as you resize the viewport.
- Does this layout technique pass accessibility audits?
- Yes. By maintaining semantic HTML document structure, screen readers process DOM nodes in order regardless of visual grid track placement.
About the author
Written by the UIFoundry Editorial Team, which researches and maintains every guide on this site. Read more about our editorial standards or contact us with corrections.
Keep reading
Modern Bento Grid Layouts: Architecting Asymmetric Dashboard Cards with CSS Grid
Step-by-step technical guide to building Apple-style Bento grid layouts. Master grid-column spans, auto-fill algorithms, and responsive mobile adaptations.
Read the guide →