Use grid-template-rows: subgrid when nested components—such as cards in a row—need their internal content to line up across shared rows. Then use align-items or align-self if you also need to position an item within its grid area. Subgrid shares track geometry; it does not, by itself, center content.
Align repeated rows across cards with row subgrid
Suppose each card contains a title, description, and link. If descriptions have different lengths, an ordinary grid inside each card sizes its rows independently, so the links may not line up. A row subgrid lets the cards use the parent grid’s row tracks instead.
<div class="cards">
<article class="card">
<h2>Card title</h2>
<p>Card descriptions can have different lengths.</p>
<a href="#">Read more</a>
</article>
<article class="card">
<h2>Another title</h2>
<p>A shorter description.</p>
<a href="#">Read more</a>
</article>
</div>
.cards {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
grid-template-rows: auto 1fr auto;
gap: 1rem;
}
.card {
display: grid;
grid-row: span 3;
grid-template-rows: subgrid;
}
The parent defines the rows, and each card spans three of them. Within each card, the title, description, and link occupy corresponding rows. As a result, corresponding content shares track sizing across the cards. Adjust the row definition and span to match the component and its responsive layout.
MDN Web Docs’ “Subgrid – CSS” documentation describes the key behavior: “If you set the value of subgrid on grid-template-columns, grid-template-rows or both, instead of creating a new track listing, the nested grid uses the tracks defined on the parent.”
Recommended Free Tools
#1 Best Overall
Center items inside their grid areas separately
Shared tracks do not dictate where an item sits inside its area. To align all items on the block axis, add align-items to the grid container:
.card {
display: grid;
grid-row: span 3;
grid-template-rows: subgrid;
align-items: center;
}
To align just one item, use align-self on that item:
Rank #2
.card a {
align-self: center;
}
In the usual horizontal writing mode, the block axis runs vertically. CSS grid uses logical axes, however, so “block axis” is more accurate than “vertical” when a layout may use a different writing mode.
Choose the right alignment property
| Property or feature | What it affects | Use it for |
|---|---|---|
grid-template-rows: subgrid |
The nested grid’s row tracks come from its parent. | Matching internal row sizing across nested siblings. |
align-items |
Items within their grid areas on the block axis. | Applying the same item alignment to a grid container’s children. |
align-self |
One item within its grid area on the block axis. | Overriding the container’s item alignment for a particular child. |
align-content |
The grid tracks as a group within a grid container when there is extra space. | Positioning the track group, not aligning an individual item or selecting which parent rows it spans. |
vertical-align is not a general alternative for grid or block items. MDN Web Docs’ “vertical-align CSS property” reference notes: “Note that vertical-align only applies to inline, inline-block and table-cell elements: you can’t use it to vertically align block-level elements.”
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #3
Set up the parent and subgrid correctly
- The nested element must be a grid item in its parent, and it needs
display: gridto establish its own grid formatting context. - Declare
grid-template-rows: subgridfor shared rows,grid-template-columns: subgridfor shared columns, or both if the layout needs to share tracks in both dimensions. - Make the nested grid span the parent tracks its contents need. A subgrid can use only the rows or columns covered by the parent item’s span.
- Use parent row sizing that suits the content. Content can contribute to track sizing when the sizing method permits it; auto-sized parent rows can grow to fit content from the main grid and subgrid. Subgrid therefore does not promise fixed heights.
Understand gaps and track sizing
A subgrid inherits its parent grid’s gaps by default. You can override the gap on the subgrid. In particular, setting a subgrid gap to zero can return space to an item in a way similar to a negative margin; it does not mean the parent grid’s gap has disappeared for every other item.
Likewise, shared tracks do not guarantee that every row has a predetermined height. With content-sensitive sizing, the content in the main grid and subgrid can affect track size. If you need predictable alignment, define the parent tracks and account for variable content rather than assuming that subgrid fixes component heights.
Rank #4
Troubleshoot misaligned content
- The cards still size their rows independently: Confirm the card has
display: gridandgrid-template-rows: subgrid. A nested grid without subgrid creates its own tracks. - Content does not map to the intended rows: Check that the card spans the necessary parent tracks and that the parent’s row order matches the children’s order.
- Items share rows but are not centered: Add
align-itemson the grid container oralign-selfon the specific item. Subgrid aligns tracks, not items within their areas. - The tracks are positioned unexpectedly in a tall container: Check whether the grid has free space and whether
align-contentis positioning the track group. It is not a substitute for item alignment. - Spacing differs inside the nested component: Check whether the subgrid has overridden its inherited gap. A zero subgrid gap changes spacing within that subgrid; it does not erase the parent gap elsewhere.
- Content causes row sizes to change: Review the parent’s track-sizing methods and the content contributions they allow. Auto-sized rows may expand to fit content.
vertical-alignhas no effect: Use grid alignment properties for grid items.vertical-alignapplies to inline, inline-block, and table-cell boxes, not as a general block-level alignment method.
Browser support
MDN marks subgrid as widely available across browsers and says it has been available across browsers since September 2023. That supports its use in modern browsers, but does not establish exact minimum browser versions here. Check a current compatibility table for the specific browsers and versions your project must support.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If you need a rendered screenshot to inspect a layout, ScreenshotNeo can capture a page through one API request. Its capture flow accepts cookie and consent banners like a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses identify the page verdict and billing status in headers. It also provides an MCP server with screenshot, page-info, and PDF tools for AI agents.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →For example, request a screenshot of your page with cURL:
Best Value
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
See the ScreenshotNeo API documentation for request options. One thousand screenshots per month are free with no card; paid plans start at $5 for 3,000. Sign up for a free account.
Frequently Asked Questions
Can subgrid share columns as well as rows?
Yes. Use grid-template-columns: subgrid to share the parent’s column tracks; rows and columns can be subgridded independently.
Does subgrid require fixed row heights?
No. Parent track sizing can remain content-sensitive where its sizing method allows content contributions.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




