Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk5 min

How to Vertically Align Elements With CSS Subgrid

Learn when row subgrid aligns nested component tracks, how to center grid items separately, and how to troubleshoot spans, gaps, and sizing.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.”

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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:

.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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set up the parent and subgrid correctly

  • The nested element must be a grid item in its parent, and it needs display: grid to establish its own grid formatting context.
  • Declare grid-template-rows: subgrid for shared rows, grid-template-columns: subgrid for 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.

Troubleshoot misaligned content

  • The cards still size their rows independently: Confirm the card has display: grid and grid-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-items on the grid container or align-self on 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-content is 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-align has no effect: Use grid alignment properties for grid items. vertical-align applies 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.Support on Ko-Fi

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, request a screenshot of your page with cURL:

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.