https://www.joshwcomeau.com/css/subgrid/ JoshWComeau * categories * courses * goodies * About Brand New Layouts with CSS Subgrid Filed under CSS on in November 25th, 2025. Nov 2025. Table of Contents IntroductionThe fundamentalsNew layout possibilitiesSubgrid Gotchas Reserving space for the subgridNested grid numbersIncompatibility with fluid gridsSupporting older browsersThe darkest week of the year In conclusion Introduction When CSS Grid layout was first released, it came with a big asterisk: only the grid's direct children could participate in the layout. "Subgrid" is a newer addition to CSS Grid which allows us to extend the grid layout down through the DOM tree. When I first heard about subgrid, it seemed to me like a convenience, a way to make it a bit simpler to accomplish the same stuff I was already doing. As it turns out, subgrid is way more interesting than that. It opens whole new doors in terms of the UIs we can build! In this tutorial, I'll show you some of the exciting new things we can do with subgrid. Along the way, you'll learn the basic mechanics of subgrid. We'll even go over the most common gotchas! Intended audience This blog post assumes that you understand the basics of CSS Grid layout. If you're not super comfortable with grid, you can learn the fundamentals here: * An Interactive Guide to CSS Grid Credit to Kevin Powell In preparation for this tutorial, I looked at a lot of subgrid resources, to try to see what sorts of things people were building with subgrid. The best examples I found, by far, are from YouTube superstar (and fellow Canadian!) Kevin Powell(opens in new tab). Specifically, these videos helped shape the examples we cover in this post: * "Easy and more consistent layouts using subgrid"(opens in new tab) * "You can't do this without subgrid"(opens in new tab) * "The dichotomy of grid"(opens in new tab) Link to this headingThe fundamentals We'll get to the interesting stuff soon, but first, let's start with the basics. Suppose we want to implement the following mockup: Mockup of a portfolio UI. On the left, there's a gray box with a heading and some smaller text. On the right, there's a collection of 6 pieces of artwork. The whole thing is arranged in a 4 by 2 grid, with the gray box on the left spanning two rows. We can create this layout using a flat grid, no subgrid required. Here's a quick implementation: Code Playground Reset Code Show line numbersFormat code using PrettierOpen in CodeSandbox index.html styles.css

My Portfolio

A small selection of the works created using Blender. No robots or AI involved.

In a real artist portfolio, there would be more text here.

... ... ... ... ... ...
resultconsole Refresh results pane Not a responsive layout To keep things as simple as possible, this layout is not responsive at all. Since you're viewing this on a device with a smaller screen, you may have to scroll horizontally to view some of the layouts in this tutorial. If we check the "Grid" devtools, we see that this is a 4x2 grid, with the header spanning the first two rows: Screenshot of the UI shown above, with grid lines overlaid. The lines are labeled 1 through 5 horizontally, for the 4 columns, and 1 through 3 vertically, for the 2 rows. In order for this to work without subgrid, every grid participant has to be a direct child of the .grid container. Sure enough, if we inspect the HTML, we see the following structure: Copy to clipboard

...

...

... ... ... ... ... ...
Semantically, this feels a bit funky to me. I feel like these images should be grouped in a list, since we're displaying a collection of portfolio pieces. Proper semantic markup will provide more context to folks using assistive technologies like screen readers, and to search engines that are trying to make sense of our page. Unfortunately, adding this extra markup throws a wrench into the grid: Code Playground Reset Code Show line numbersFormat code using PrettierOpen in CodeSandbox index.html styles.css

My Portfolio

A small selection of the works created using Blender. No robots or AI involved.

In a real artist portfolio, there would be more text here.

resultconsole Refresh results pane Instead of having each image occupy its own grid cell, we instead cram the entire list of images into a single cell in the second column, leaving the final two columns totally empty. CSS subgrid allows us to extend the parent grid through that