CSS Grid Snippets — Free HTML CSS JS CSS Grid Layout Examples

362 snippets tagged CSS Grid · Live preview · Exports to React, Vue, Angular & Tailwind

What's included

Features

auto-fit / minmax responsive card grids that need no media queries
Bento-box sections built from spanning grid items
Named grid-template-areas for readable page and dashboard shells
Masonry-style galleries via grid-auto-flow: dense and row spanning
gap, alignment and subgrid usage that keeps nested content aligned

About this tag

CSS Grid Snippets — 362 Free CSS Grid Layout Examples

CSS Grid is the first layout system on the web that lets you describe a two-dimensional arrangement directly instead of approximating it. These snippets use it for what it is best at: bento-box feature sections, dashboard shells, card galleries that reflow without media queries, and page layouts defined as named template areas you can read at a glance.

The recurring trick is repeat(auto-fit, minmax(...)) — a grid that decides its own column count from the available width, which removes most breakpoint maintenance from a card layout.

Two dimensions, described directly

Before Grid, a two-dimensional layout meant nesting flexbox containers or relying on float-based hacks to approximate rows and columns together. Grid lets a single declaration describe both axes at once — track sizes, gaps and item placement — which is why a bento-box section with items of varying size is a handful of grid-column and grid-row spans rather than a nest of wrapper divs.

auto-fit and minmax removing breakpoints

repeat(auto-fit, minmax(240px, 1fr)) tells the browser to fit as many 240px-minimum columns as the container allows, stretching them to fill any remaining space, and to collapse to fewer columns as the viewport narrows — all without a single @media query. This one line is doing the job that used to take three separate breakpoints per card grid, and it never produces the orphaned single-item row that a fixed column count does at odd widths.

Named areas as a legible layout language

grid-template-areas lets a layout be described as a literal ASCII diagram of named regions — "header header" / "sidebar content" / "footer footer" — and the elements assigned to each area follow that shape without any additional positioning code. Reading the stylesheet tells you the actual page structure at a glance, which is a real advantage over inferring the same structure from nested markup and margins.

Where Grid's limits show up

CSS still has no native masonry layout in every browser, so packing items of different heights into a Pinterest-style grid uses grid-auto-flow: dense with varied row spans as a convincing approximation rather than true masonry. And Grid composes with, rather than replaces, Flexbox: a page-level grid shell whose individual cells lay out their own content with flex is the most common and most maintainable real-world combination.

Real-world uses

Common Use Cases

Bento feature sections
The layout every product page now uses, and Grid is the only clean way to express it.
Dashboard and app shells
Sidebar, header and content as named areas makes the layout legible in the stylesheet instead of implied by nesting.
Responsive card galleries
One auto-fit declaration replaces three breakpoints and never has an awkward orphan column.
Learning Grid properly
Template areas, spanning and implicit tracks are far easier to understand when you can edit them live.

Got questions?

Frequently Asked Questions

auto-fit collapses empty tracks so the remaining items stretch to fill the row; auto-fill keeps the empty tracks, leaving a gap where more items would go. For a card grid that should always look full, auto-fit is usually what you want.

Grid when you are placing content in two dimensions — rows and columns together. Flexbox for a single line of items that should distribute along one axis. They compose well: a grid page shell whose individual cells use flex internally is the most common real-world combination.

Not natively yet in all browsers. The practical approach in these snippets is grid-auto-flow: dense with varied row spans, which fills gaps convincingly for image galleries. True masonry needs a script or the still-shipping CSS masonry syntax.

No. Every snippet is plain HTML, CSS and vanilla JavaScript that runs in any page — a static file, a WordPress theme, a Rails view, anything. When you do want a framework version, the editor exports each snippet as a React component, a React + Tailwind component, a standalone Tailwind HTML file, a Vue 3 single-file component or an Angular standalone component.

Yes — copy, modify and ship them in personal or commercial work, with no attribution required and no licence to track.

Yes. Every snippet opens in a live editor with separate HTML, CSS and JS panels and a preview that updates as you type. Check it at mobile, tablet and desktop widths, then copy the code or export it in your framework of choice.