Subgrid

Subgrid lets you use CSS Subgrid easily without the configuration headaches.


Subgrids that are super simple to use — no complexity

No need to define the subgrid on grid-template-columns, grid-template-rows, inheriting gap, and all the configuration nonsense. We do that all for you with the Subgrid class.

index.html
<div class="Subgrid">...</div>
main.css
/* Properties already created for you */
.Subgrid {
display: grid;
grid-template-columns: subgrid;
grid-template-rows: subgrid;
grid-column: var(--start, auto) / span var(--span, 1);
grid-row: var(--rowstart, auto) / span var(--rowspan, 1);
gap: inherit;
/* ... and other properties ... */
}

Subgrids in one (or two) directions!

You only need subgrid for one direction most of the time — so we created Subgrid-columns and Subgrid-rows to cater to that use case. But if you need to subgrids in both directions, we’ve got that covered too.

index.html
<div class="Subgrid-columns"><!-- Subgrid columns only --></div>
<div class="Subgrid-rows"><!-- Subgrid rows only --></div>
<div class="Subgrid"><!-- Subgrid for both directions --></div>
main.css
/* Column-only subgrid */
.Subgrid-columns {
display: grid;
grid-template-columns: subgrid;
grid-column: var(--start, auto) / span var(--span, 1);
gap: inherit;
/* ... and other properties ... */
}
/* Row-only subgrid */
.Subgrid-rows {
display: grid;
grid-template-rows: subgrid;
grid-row: var(--rowstart, auto) / span var(--rowspan, 1);
gap: inherit;
/* ... and other properties ... */
}

Arrange grid items neatly on both axes

Just use Subgrid-rows and specify the number of elements in the subgrid as the --rowspan variable and everything will be neatly arranged.

index.html
<div class="SimpleGrid [--cols:2]">
<div class="Subgrid-rows [--rowspan:3]">
<h3>Title</h3>
<p>Description</p>
<button>Button</button>
</div>
<div class="Subgrid-rows [--rowspan:3]">
<h3>Title</h3>
<p>Description</p>
<button>Button</button>
</div>
</div>
Title 1
Short description: Lorem ipsum dolor sit.
Title 2
Medium desc: Lorem ipsum dolor, sit amet consectetur adipisicing elit.

Make stuff you can’t do with display: contents

Subgrid-columns let you use the same number of columns, but create multiple rows — while the parent still thinks it’s one!

index.html
<div class="SimpleGrid [--cols:4]">
<div>Grid item</div>
<div class="Subgrid-columns [--span:3]">
<div>Nested Item 1</div>
<div class="[--ispan:2]">Nested Item 2</div>
<div class="[--ispan:3]">Nested Item 3</div>
</div>
</div>

Use --ispan to configure the number of columns the grandchild element should occupy.

Subgrid
1 Row
Grid item
Nested Item 1
Nested Item 2
Nested Item 3
Display: Contents
Two rows
Grid item
Nested Item 1
Nested Item 2
Nested Item 3

Want nested subgrids? No problem!

Go crazy and creative and make as many whacky grids as you would like. Subgrid can support them all — and still keep you sane.

This was created with 6 Subgrid rows
Short
Medium
Long
Medium
Medium
Medium
Long
Medium
Short

This is a pretty complex 10-column grid. It’s created with 2 nested subgrid-column

AG1
AG2
AG4
AG5
AG6
AG7
AG8
AG9
AG10
AG3