Skip to content

Grid Utility

CSS Grid layout classes included in @grundtone/design-tokens. Import the design-tokens CSS to use them – see Installation for setup. Examples below have a Code / Preview tab.


Basic Usage

1. Create a grid container

Add grid to enable grid layout. Without grid-cols-N, items stack vertically:

Item 1
Item 2
Item 3

2. Set number of columns

Use grid-cols-N (1–12):

1
2
3
4
5
6

3. Add gap between items

Use gap-N for both row and column gap:

gap-8
gap-8
gap-8
gap-8
gap-8
gap-8

The gap scale is shared by gap-N, gap-x-N (column only), and gap-y-N (row only):

SuffixValueSuffixValueSuffixValue
0041rem112.75rem
px1px51.25rem123rem
0-50.125rem61.5rem143.5rem
10.25rem71.75rem164rem
1-50.375rem82rem205rem
20.5rem92.25rem246rem
2-50.625rem102.5rem
30.75rem
3-50.875rem

Columns and rows

Columns and rows are independent axes – columns run horizontally, rows run vertically. There is no dependency between them.

  • Columns – You typically set grid-cols-N to define the layout. Rows are created implicitly as items flow in (left-to-right, top-to-bottom).
  • Rows – Use grid-rows-N only when you need explicit row control (e.g. fixed header + flexible main area). Otherwise rows are auto-sized.
  • col-span vs row-spancol-span-N spans columns (horizontal). row-span-N spans rows (vertical). You can use both on the same item.

Row span – one item spans multiple rows (in its column). Here, A fills two rows in the first column:

A (2 rows)
B
C
D
E
F

Col + row span – same item spans columns and rows:

Wide + tall
1
2
3
4
5

Column Span

Make an item span multiple columns with col-span-N:

Main content (8 cols)
Sidebar (4 cols)

Full width with col-span-full:

Full width (col-span-full)
1
2
3

Column Start / End

Place items at specific column lines with col-start-N and col-end-N (1–13):

col-start-2 col-end-6
col-start-1 col-end-4
col-start-4 col-end-7

Auto Flow

Control how items are placed in the grid. Default is row flow (left-to-right, top-to-bottom). Use grid-flow-col to flow by column instead:

1
2
3
4
5
6

Add grid-flow-dense to fill gaps when items have varying spans.


Centering

grid-center places all items at the center of their cell:

Centered

Responsive Grid

Add a breakpoint prefix before any grid class to apply it only at that viewport width and up. Format: {breakpoint}: + class, e.g. md:grid-cols-3 or lg:col-span-6.

Breakpoints (min-width): sm 640px, md 768px, lg 1024px, xl 1280px, 2xl 1536px.

Mobile-first: Base classes apply to all sizes. Prefixed classes apply from that breakpoint and up. Example: grid-cols-1 md:grid-cols-2 lg:grid-cols-3 = 1 column by default, 2 from 768px, 3 from 1024px.

Note: sm: supports grid-cols-1grid-cols-6, col-span-1col-span-6, and col-start/end-1col-start/end-7. The md:, lg:, xl:, and 2xl: breakpoints support the full 1–12/13 range. Gap, grid-flow, and auto-cols/rows also have responsive variants at all breakpoints.

1
2
3
4
5
6

Responsive column span – full width on mobile, then 8 cols, then 6:

Responsive width
Fills rest

Preset Layouts

Preset layouts use spacing variables (--space-md, --space-lg, --space-xl) for their built-in gap. Override these in :root to adjust spacing globally.

Auto-fit (responsive columns)

Columns grow/shrink with viewport. Min column width is configurable via --grid-auto-fit-min (default 250px).

Card 1
Card 2
Card 3

grid-auto-fill works the same way but uses auto-fill instead of auto-fit — empty tracks are preserved rather than collapsed:

1
2

Card grid

Predefined auto-fit for cards. Style the card children yourself — the grid only controls column width and gap.

ClassMin column widthGap
grid-cards-sm200px--space-md
grid-cards280px--space-lg
grid-cards-lg360px--space-xl
Card 1
Card 2
Card 3
Main content (flexible)
Main content

Holy grail layout

Header, nav, main, aside, footer. Uses named grid areas (grid-header, grid-nav, grid-main, grid-aside, grid-footer):

Header
Main
Footer

Class Reference

Container

ClassDescription
griddisplay: grid
grid-cols-1grid-cols-12Column count
grid-cols-noneNo explicit columns
grid-cols-subgridSubgrid columns
grid-rows-1grid-rows-6Row count
grid-rows-noneNo explicit rows
grid-rows-subgridSubgrid rows

Gap

ClassDescription
gap-0gap-24Row and column gap
gap-x-NColumn gap only
gap-y-NRow gap only

See gap scale for all available values.

Column span

ClassDescription
col-span-1col-span-12Span N columns
col-span-fullFull width (1 / -1)
col-autoAuto placement

Column start / end

ClassDescription
col-start-1col-start-13Start at column line N
col-start-autoAuto start
col-end-1col-end-13End at column line N
col-end-autoAuto end

Row span

ClassDescription
row-span-1row-span-6Span N rows
row-span-fullFull height
row-autoAuto placement

Row start / end

ClassDescription
row-start-1row-start-7Start at row line N
row-start-autoAuto start
row-end-1row-end-7End at row line N
row-end-autoAuto end

Auto flow

ClassDescription
grid-flow-rowFlow items by row (default)
grid-flow-colFlow items by column
grid-flow-denseDense packing
grid-flow-row-denseRow flow with dense packing
grid-flow-col-denseColumn flow with dense packing

Auto columns / rows

ClassDescription
auto-cols-autogrid-auto-columns: auto
auto-cols-mingrid-auto-columns: min-content
auto-cols-maxgrid-auto-columns: max-content
auto-cols-frgrid-auto-columns: minmax(0, 1fr)
auto-rows-autogrid-auto-rows: auto
auto-rows-mingrid-auto-rows: min-content
auto-rows-maxgrid-auto-rows: max-content
auto-rows-frgrid-auto-rows: minmax(0, 1fr)

Preset layouts

ClassDescription
grid-auto-fitResponsive columns (auto-fit, min 250px)
grid-auto-fillSame as auto-fit but preserves empty tracks
grid-cards-smCard grid, min 200px
grid-cardsCard grid, min 280px
grid-cards-lgCard grid, min 360px
grid-sidebar-leftSidebar (auto) + main (1fr)
grid-sidebar-rightMain (1fr) + sidebar (auto)
grid-holy-grailHeader, nav, main, aside, footer
grid-centerplace-items: center
grid-stretchplace-items: stretch

Responsive prefix

Prepend {breakpoint}: to any class to apply it from that viewport width up. Works with grid-cols, col-span, col-start/end, row-span/start/end, gap, and grid-flow. sm: supports 1–6 columns/spans; md: and above support 1–12. See Responsive Grid for details.

For alignment, ordering, and display utilities, see Columns & Layout.


Custom breakpoints

The default breakpoints can be overridden via CSS variables. See Theme Configuration for details.


Custom min width (auto-fit)

Override the default 250px globally in :root or inline per element:

150px min
150px min
150px min
150px min