ItemGrid
A list of equal items whose last row is decided, not left over. Twelve tracks on the site gap: three columns from 60rem, two from 36rem, one below — measured on the grid's own width, so it works in a main column, a sidebar or a card. Only the spans change; the order you write is the order it reads.
The last row, left over
A list of equal items is usually laid out with auto-fit: the full rows fill and the last one is left to chance. Seven items end as 4 / 3 at one width and 3 / 3 / 1 at the next, and the edges meet the site grid only by coincidence. Resize the window and watch the last row.
---
import Teaser from "tsugite/Teaser/Teaser.astro";
import img1 from "../../assets/media/amal-s.jpg";
import img2 from "../../assets/media/david-becker.jpg";
import img3 from "../../assets/media/jean-philippe.jpg";
const images = [img1, img2, img3];
const items = [
"Joinery without nails",
"One truth at a time",
"The odd one out",
"Grain and direction",
"A seam you can see",
"Cut once",
"The last row",
];
---
{/* The usual grid: auto-fit fills the full rows and leaves the last one to chance. */}
<ul style="list-style:none; margin:0; padding:0; display:grid; grid-template-columns:repeat(auto-fit, minmax(18rem, 1fr)); gap:var(--grid-layout-gap);">
{items.map((heading, i) => (
<li style="display:grid;">
<Teaser image={images[i % 3]} alt="" heading={heading} href="#" excerpt="Short excerpt giving a taste of the content." />
</li>
))}
</ul>Balance — the default
A lone leftover borrows one item from the row above, so the last four share two rows: 3 / 2 / 2, never 3 / 3 / 1. Two leftovers share their row.
---
import ItemGrid from "tsugite/ItemGrid/ItemGrid.astro";
import ItemGridItem from "tsugite/ItemGrid/ItemGridItem.astro";
import Teaser from "tsugite/Teaser/Teaser.astro";
import img1 from "../../assets/media/amal-s.jpg";
import img2 from "../../assets/media/david-becker.jpg";
import img3 from "../../assets/media/jean-philippe.jpg";
const images = [img1, img2, img3];
const items = [
"Joinery without nails",
"One truth at a time",
"The odd one out",
"Grain and direction",
"A seam you can see",
"Cut once",
"The last row",
].slice(0, 7);
---
{/* balance, the default: a lone leftover borrows one from the row above — 3 / 2 / 2. */}
<ItemGrid>
{items.map((heading, i) => (
<ItemGridItem>
<Teaser image={images[i % 3]} alt="" heading={heading} href="#" excerpt="Short excerpt giving a taste of the content." />
</ItemGridItem>
))}
</ItemGrid>Split
The leftovers bookend the grid: one pair opens and one closes, 2 / 3 / 2. Two leftovers open it, 2 / 3.
---
import ItemGrid from "tsugite/ItemGrid/ItemGrid.astro";
import ItemGridItem from "tsugite/ItemGrid/ItemGridItem.astro";
import Teaser from "tsugite/Teaser/Teaser.astro";
import img1 from "../../assets/media/amal-s.jpg";
import img2 from "../../assets/media/david-becker.jpg";
import img3 from "../../assets/media/jean-philippe.jpg";
const images = [img1, img2, img3];
const items = [
"Joinery without nails",
"One truth at a time",
"The odd one out",
"Grain and direction",
"A seam you can see",
"Cut once",
"The last row",
].slice(0, 7);
---
{/* split: the leftovers bookend the grid — 2 / 3 / 2. */}
<ItemGrid remainder="split">
{items.map((heading, i) => (
<ItemGridItem>
<Teaser image={images[i % 3]} alt="" heading={heading} href="#" excerpt="Short excerpt giving a taste of the content." />
</ItemGridItem>
))}
</ItemGrid>Fill
The leftovers share the whole row. A Teaser given that width lies down by its own container query; the grid only allocates the width.
---
import ItemGrid from "tsugite/ItemGrid/ItemGrid.astro";
import ItemGridItem from "tsugite/ItemGrid/ItemGridItem.astro";
import Teaser from "tsugite/Teaser/Teaser.astro";
import img1 from "../../assets/media/amal-s.jpg";
import img2 from "../../assets/media/david-becker.jpg";
import img3 from "../../assets/media/jean-philippe.jpg";
const images = [img1, img2, img3];
const items = [
"Joinery without nails",
"One truth at a time",
"The odd one out",
"Grain and direction",
"A seam you can see",
"Cut once",
"The last row",
].slice(0, 4);
---
{/* fill: the leftover takes the whole row. */}
<ItemGrid remainder="fill">
{items.map((heading, i) => (
<ItemGridItem>
<Teaser image={images[i % 3]} alt="" heading={heading} href="#" excerpt="Short excerpt giving a taste of the content." />
</ItemGridItem>
))}
</ItemGrid>Inset
As fill, with one column of air at each side.
---
import ItemGrid from "tsugite/ItemGrid/ItemGrid.astro";
import ItemGridItem from "tsugite/ItemGrid/ItemGridItem.astro";
import Teaser from "tsugite/Teaser/Teaser.astro";
import img1 from "../../assets/media/amal-s.jpg";
import img2 from "../../assets/media/david-becker.jpg";
import img3 from "../../assets/media/jean-philippe.jpg";
const images = [img1, img2, img3];
const items = [
"Joinery without nails",
"One truth at a time",
"The odd one out",
"Grain and direction",
"A seam you can see",
"Cut once",
"The last row",
].slice(0, 4);
---
{/* inset: as fill, with one column of air at each side. */}
<ItemGrid remainder="inset">
{items.map((heading, i) => (
<ItemGridItem>
<Teaser image={images[i % 3]} alt="" heading={heading} href="#" excerpt="Short excerpt giving a taste of the content." />
</ItemGridItem>
))}
</ItemGrid>Center
The leftovers keep the size of the full rows' items, centred.
---
import ItemGrid from "tsugite/ItemGrid/ItemGrid.astro";
import ItemGridItem from "tsugite/ItemGrid/ItemGridItem.astro";
import Teaser from "tsugite/Teaser/Teaser.astro";
import img1 from "../../assets/media/amal-s.jpg";
import img2 from "../../assets/media/david-becker.jpg";
import img3 from "../../assets/media/jean-philippe.jpg";
const images = [img1, img2, img3];
const items = [
"Joinery without nails",
"One truth at a time",
"The odd one out",
"Grain and direction",
"A seam you can see",
"Cut once",
"The last row",
].slice(0, 4);
---
{/* center: the leftover keeps its size, centred. */}
<ItemGrid remainder="center">
{items.map((heading, i) => (
<ItemGridItem>
<Teaser image={images[i % 3]} alt="" heading={heading} href="#" excerpt="Short excerpt giving a taste of the content." />
</ItemGridItem>
))}
</ItemGrid>Start
The leftovers keep their size and stand at the start — the plain grid, chosen rather than left over.
---
import ItemGrid from "tsugite/ItemGrid/ItemGrid.astro";
import ItemGridItem from "tsugite/ItemGrid/ItemGridItem.astro";
import Teaser from "tsugite/Teaser/Teaser.astro";
import img1 from "../../assets/media/amal-s.jpg";
import img2 from "../../assets/media/david-becker.jpg";
import img3 from "../../assets/media/jean-philippe.jpg";
const images = [img1, img2, img3];
const items = [
"Joinery without nails",
"One truth at a time",
"The odd one out",
"Grain and direction",
"A seam you can see",
"Cut once",
"The last row",
].slice(0, 4);
---
{/* start: the leftover keeps its size, at the start. */}
<ItemGrid remainder="start">
{items.map((heading, i) => (
<ItemGridItem>
<Teaser image={images[i % 3]} alt="" heading={heading} href="#" excerpt="Short excerpt giving a taste of the content." />
</ItemGridItem>
))}
</ItemGrid>Element
A ul by default, or an ol or a div; each item stands in an ItemGridItem, an li or a div to match. A list keeps its list role (role="list"), which WebKit drops once the markers are off; a div has none.
---
import ItemGrid from "tsugite/ItemGrid/ItemGrid.astro";
import ItemGridItem from "tsugite/ItemGrid/ItemGridItem.astro";
import Teaser from "tsugite/Teaser/Teaser.astro";
import img1 from "../../assets/media/amal-s.jpg";
import img2 from "../../assets/media/david-becker.jpg";
import img3 from "../../assets/media/jean-philippe.jpg";
const images = [img1, img2, img3];
const items = [
"Joinery without nails",
"One truth at a time",
"The odd one out",
"Grain and direction",
"A seam you can see",
"Cut once",
"The last row",
].slice(0, 5);
---
{/* A div grid with div cells: no list, so no list role. The cell's element follows the grid's. */}
<ItemGrid element="div">
{items.map((heading, i) => (
<ItemGridItem element="div">
<Teaser image={images[i % 3]} alt="" heading={heading} href="#" excerpt="Short excerpt giving a taste of the content." />
</ItemGridItem>
))}
</ItemGrid>Every value on every count and column state is on the test bench.





