Grid
CSS Grid layout utilities - columns, rows, spans, placement, alignment, auto-flow, and gap.
Basic grid
Use .grid to create a block-level grid container (sets display: grid; gap: 1rem). Combine with .grid-cols-{n} to define the number of columns. ArchCSS uses a 12-column grid system.
<div class="grid grid-cols-3">
<div>Card 1</div>
<div>Card 2</div>
<div>Card 3</div>
<div>Card 4</div>
<div>Card 5</div>
<div>Card 6</div>
</div>
Column count
Column classes are generated from $grid-design: 12, giving you .grid-cols-1 through .grid-cols-12. Each sets grid-template-columns: repeat(n, minmax(0, 1fr)).
| Class | CSS Output |
|---|---|
.grid-cols-1 | grid-template-columns: repeat(1, minmax(0, 1fr)) |
.grid-cols-2 | grid-template-columns: repeat(2, minmax(0, 1fr)) |
.grid-cols-3 | grid-template-columns: repeat(3, minmax(0, 1fr)) |
.grid-cols-4 | grid-template-columns: repeat(4, minmax(0, 1fr)) |
.grid-cols-5 | grid-template-columns: repeat(5, minmax(0, 1fr)) |
.grid-cols-6 | grid-template-columns: repeat(6, minmax(0, 1fr)) |
.grid-cols-7 | grid-template-columns: repeat(7, minmax(0, 1fr)) |
.grid-cols-8 | grid-template-columns: repeat(8, minmax(0, 1fr)) |
.grid-cols-9 | grid-template-columns: repeat(9, minmax(0, 1fr)) |
.grid-cols-10 | grid-template-columns: repeat(10, minmax(0, 1fr)) |
.grid-cols-11 | grid-template-columns: repeat(11, minmax(0, 1fr)) |
.grid-cols-12 | grid-template-columns: repeat(12, minmax(0, 1fr)) |
.col-span-{n} | grid-column: span n / span n |
.row-span-{n} | grid-row: span n / span n |
All column classes support responsive prefixes for mobile-first layouts:
<!-- 1 col mobile -> 2 col md -> 4 col lg -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
Gap utilities
Control spacing between grid cells using gap utilities. .g-{n} sets both row and column gap. .gx-{n} sets column gap only. .gy-{n} sets row gap only. Values range from 0 to 6.
| Class | CSS Property | Value |
|---|---|---|
.g-0 | gap | 0 |
.g-1 | gap | 0.25rem |
.g-2 | gap | 0.5rem |
.g-3 | gap | 1rem |
.g-4 | gap | 1.5rem |
.g-5 | gap | 2rem |
.g-6 | gap | 3rem |
.gx-{n} | column-gap | same scale |
.gy-{n} | row-gap | same scale |
g-1 (tight)
g-4 (comfortable)
<!-- Uniform gap -->
<div class="grid grid-cols-3 g-4">...</div>
<!-- Different column and row gaps -->
<div class="grid grid-cols-3 gx-4 gy-2">...</div>
Responsive grid
Combine grid and gap utilities with responsive prefixes to build adaptive card layouts. The example below stacks on mobile, becomes 2 columns at md, and 3 columns at lg.
Card Title
Short description text goes here.
Card Title
Short description text goes here.
Card Title
Short description text goes here.
<div class="grid md:grid-cols-2 lg:grid-cols-3 g-3">
<div class="card">
<img src="..." alt="...">
<h3>Card Title</h3>
<p>Description</p>
</div>
<!-- repeat for more cards... -->
</div>
Tip: Use.inline-gridinstead of.gridwhen you need the container itself to shrink to fit its content, rather than stretching to the full available width.
Placement
Position and size individual grid items within the track lines. .col-span-{n} and .row-span-{n} stretch an item across n tracks; .col-start-{n}, .col-end-{n}, .row-start-{n}, and .row-end-{n} pin items to specific line numbers.
<div class="grid grid-cols-3 gap-3">
<div class="col-span-2">Spans 2 columns</div>
<div>Normal cell</div>
<div class="col-start-2 col-end-4">From line 2 to line 4</div>
<div class="row-span-2">Spans 2 rows</div>
<div>Cell</div>
</div>
| Class | CSS Property | Keys |
|---|---|---|
.col-span-{n} | grid-column | 1 to 12, responsive |
.col-start-{n} | grid-column-start | 1 to 12, responsive |
.col-end-{n} | grid-column-end | 1 to 12, responsive |
.row-span-{n} | grid-row | 1 to 6, responsive |
.row-start-{n} | grid-row-start | 1 to 6, responsive |
.row-end-{n} | grid-row-end | 1 to 6, responsive |
Alignment
Align the whole grid or a single cell with .place-items-* and .place-self-*. For inline-axis justify-items-* / justify-self-* equivalents, see the Flexbox page - they apply to grid containers too.
| Class | CSS Property |
|---|---|
.place-items-start | place-items: start |
.place-items-end | place-items: end |
.place-items-center | place-items: center |
.place-items-stretch | place-items: stretch |
.place-self-start | place-self: start |
.place-self-end | place-self: end |
.place-self-center | place-self: center |
.place-self-stretch | place-self: stretch |
Auto-fit and auto-fill
Let the grid wrap items into as many equal columns as fit, each at least {px} wide. .grid-fill-{px} uses auto-fill (keeps ghost tracks), .grid-fit-{px} uses auto-fit (collapses empty tracks). Built-in widths: 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, and 300.
<div class="grid grid-fit-200">
<div class="card">Card</div>
<div class="card">Card</div>
<div class="card">Card</div>
</div>
Resize the page to see the columns reflow. Use a width around the size of your smallest card so items never crush below it.
Advanced grid
Content-sized columns, row templates, auto-flow, and resets.
| Class | CSS Property | Notes |
|---|---|---|
.grid-columns-{n} | grid-template-columns | repeat(auto, n) content-sized columns |
.grid-rows-{n} | grid-template-rows | 1 to 6, responsive |
.grid-flow-column | grid-auto-flow: column | place items along columns |
.grid-flow-row | grid-auto-flow: row | placement along rows |
.grid-flow-dense | grid-auto-flow: dense | fill holes before sparse items |
.grid-flow-row-dense | grid-auto-flow: row dense | inline fill then dense rows |
.grid-flow-column-dense | grid-auto-flow: column dense | block fill then dense columns |
.grid-none | grid-template: none | remove the template entirely |
.grid-columns-none | grid-template-columns: none | remove only the column template |
.grid-rows-none | grid-template-rows: none | remove only the row template |
<div class="grid grid-cols-3 grid-flow-dense">
<div class="col-span-2">Wide cell</div>
<div>Cell</div>
<div>Cell</div>
</div>
<!-- Content-sized columns, not 1fr -->
<div class="grid grid-columns-3">
<div>Fits content</div>
<div>Fits content</div>
</div>
<!-- Reset a grid template -->
<div class="grid grid-columns-none">...</div>
Note:.grid-cols-{n}produces equal, fluid1frcolumns, while.grid-columns-{n}sizes columns to their content (repeat(auto, n)). The names differ only in the s character.