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.

Card 1
Card 2
Card 3
Card 4
Card 5
Card 6
<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-1grid-template-columns: repeat(1, minmax(0, 1fr))
.grid-cols-2grid-template-columns: repeat(2, minmax(0, 1fr))
.grid-cols-3grid-template-columns: repeat(3, minmax(0, 1fr))
.grid-cols-4grid-template-columns: repeat(4, minmax(0, 1fr))
.grid-cols-5grid-template-columns: repeat(5, minmax(0, 1fr))
.grid-cols-6grid-template-columns: repeat(6, minmax(0, 1fr))
.grid-cols-7grid-template-columns: repeat(7, minmax(0, 1fr))
.grid-cols-8grid-template-columns: repeat(8, minmax(0, 1fr))
.grid-cols-9grid-template-columns: repeat(9, minmax(0, 1fr))
.grid-cols-10grid-template-columns: repeat(10, minmax(0, 1fr))
.grid-cols-11grid-template-columns: repeat(11, minmax(0, 1fr))
.grid-cols-12grid-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
2
3
4
5
6
7
8
<!-- 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-0gap0
.g-1gap0.25rem
.g-2gap0.5rem
.g-3gap1rem
.g-4gap1.5rem
.g-5gap2rem
.g-6gap3rem
.gx-{n}column-gapsame scale
.gy-{n}row-gapsame scale

g-1 (tight)

A
B
C
D

g-4 (comfortable)

A
B
C
D
<!-- 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-grid instead of .grid when 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.

col-span-2
1
col-start-2 col-end-4
<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-column1 to 12, responsive
.col-start-{n}grid-column-start1 to 12, responsive
.col-end-{n}grid-column-end1 to 12, responsive
.row-span-{n}grid-row1 to 6, responsive
.row-start-{n}grid-row-start1 to 6, responsive
.row-end-{n}grid-row-end1 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-startplace-items: start
.place-items-endplace-items: end
.place-items-centerplace-items: center
.place-items-stretchplace-items: stretch
.place-self-startplace-self: start
.place-self-endplace-self: end
.place-self-centerplace-self: center
.place-self-stretchplace-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.

Card
Card
Card
Card
<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-columnsrepeat(auto, n) content-sized columns
.grid-rows-{n}grid-template-rows1 to 6, responsive
.grid-flow-columngrid-auto-flow: columnplace items along columns
.grid-flow-rowgrid-auto-flow: rowplacement along rows
.grid-flow-densegrid-auto-flow: densefill holes before sparse items
.grid-flow-row-densegrid-auto-flow: row denseinline fill then dense rows
.grid-flow-column-densegrid-auto-flow: column denseblock fill then dense columns
.grid-nonegrid-template: noneremove the template entirely
.grid-columns-nonegrid-template-columns: noneremove only the column template
.grid-rows-nonegrid-template-rows: noneremove 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, fluid 1fr columns, while .grid-columns-{n} sizes columns to their content (repeat(auto, n)). The names differ only in the s character.