col-start 1 / col-end 8

The layout grid for CSS

Stay on the grid. Break out of it.

Keep text at a readable width and let anything reach the edges of the screen. One grid for the whole page, no wrappers.

col-start 9 / og-view-end
get starteddocs
col-start 1 / col-end 6

get started

npm install outgrid

under half a kilobyte, minified and gzipped

view on npm
col-start 7 / frame-end
/* plain CSS */
@import "outgrid";

/* Tailwind CSS v4 */
@import "tailwindcss";
@import "outgrid/tailwind";

The idea

col-start 1 / col-end 8

One grid for the whole page, from edge to edge.

Text stays at a readable width, images and bands reach the edges of the screen, and everything lines up on the same columns. No wrappers, no nested containers: a class decides how far an element goes.

col-start 1 / col-end 4Plain CSS, or Tailwind CSS v4 utilities with variants such as md:og-view.
col-start 5 / col-end 8Every rule has zero specificity, so your own classes always win.
col-start 9 / frame-endColumns, width and gutters are custom properties: change them for the whole page or for one section.

Breakouts

col-start 1 / col-end 8

Leave the frame, reach the view.

The frame is the readable width of the content, the view is the width of the screen. Four classes decide where an element sits: on the view, on one side of it, or back on the frame. Whatever doesn't break out stays on the columns.

col-start 1 / col-end 4

Spans the frame, then negative margins push it out by --og-frame-gap on each side, to both edges of the screen. Covers, bands, full-width media.

Reaches the start edge of the view, the left one in left-to-right layouts, and ends on its own grid-column-end: here column 8. The text beside it stays on the frame.

The mirror of og-view-start: it starts on its own grid-column-start, here column 5, and reaches the end edge of the view.

Puts an element back on the frame, cancelling a breakout. Pair it with a breakpoint, as in og-view md:og-frame with Tailwind.

col-start 5 / frame-end
<section class="og-grid">
  <div class="og-view">…</div>
</section>
og-view

Frame padding

col-start 1 / col-end 8

Edge to edge, still on the frame.

A breakout takes the box out to the view. Frame padding brings its content back: the background reaches the screen, the text starts and ends where the frame does. It works on any full-width element, inside a grid or not.

col-start 1 / col-end 4

Pads both sides by --og-frame-gap. On an og-view band the background touches both edges, and the content sits exactly on the frame.

Pads the start side only: the content starts where the frame does and runs to the end edge of the screen.

Pads the end side only: the content runs from the start edge of the screen and stops where the frame does.

col-start 5 / frame-end
<section class="og-grid">
  <div class="og-view og-pad-frame">…</div>
</section>
og-view og-pad-frame
content

Subgrid

col-start 1 / col-end 8

Nest it, keep the columns.

og-subgrid spans the frame and hands the grid's columns down to its children. Every section of this page is one: its cards sit on the columns of the page, with no grid of their own.

col-start 1 / col-end 6
  • Its children are placed on the columns of the parent grid, with its gutter. col-start 3, frame-end and the other lines keep their names.
  • Breakouts work inside it: og-view, og-view-start and og-view-end still reach the edges of the screen.
  • The rows are its own, spaced by --og-gutter-y as in og-grid.
  • Give it its own grid-column and it can be narrower than the frame: its children use the columns it spans.
col-start 7 / frame-end
<main class="og-grid">
  <section class="og-subgrid">
    <h2 style="grid-column: col-start 1 / col-end 6">…</h2>
    <p style="grid-column: col-start 7 / frame-end">…</p>
    <img class="og-view" src="/band.webp" alt="" />
  </section>
</main>

Custom properties

col-start 1 / col-end 8

Set it once, change it anywhere.

The whole grid lives in custom properties. Set them on :root for every grid of the page, or on one element for that grid and what's inside it.

col-start 1 / col-end 6
  • --og-columnsdefault 12

    Number of columns.

  • --og-max-widthdefault 80rem

    Width of the frame, without the padding.

  • --og-paddingdefault 1rem

    Space between the frame and the edges of the screen.

  • --og-gutter-xdefault clamp(0.5rem, 2.2vw, 2rem)

    Gap between columns.

  • --og-gutter-ydefault clamp(0.5rem, 2.2vw, 2rem)

    Gap between rows.

  • --og-frame-gapdefault max(var(--og-padding), calc((100vw - var(--og-max-width)) / 2))

    Distance from the frame edge to the screen edge. It's computed, not meant to be set: og-grid computes it again on itself, so a width or a padding set on a grid reaches its breakouts.

col-start 7 / frame-end
:root {
  --og-max-width: 72rem;
  --og-padding: clamp(1rem, 4vw, 3rem);
}

@media (width < 48rem) {
  :root {
    --og-columns: 4;
  }
}

Tailwind CSS

col-start 1 / col-end 8

Same grid, with variants.

outgrid/tailwind declares the same classes as Tailwind CSS v4 utilities. Import it after Tailwind and every class takes a variant: break out on mobile, come back to the frame from md up.

col-start 1 / col-end 6
  • Every class works with variants: md:og-view, lg:og-frame, hover:og-view-end.
  • Only the classes the project uses end up in the CSS. The custom properties sit on :root, in @layer base.
  • Set the custom properties as any other value, with arbitrary properties such as [--og-columns:4], at any breakpoint.
  • The rules still have zero specificity: a utility on the same property wins. px-6 beats the padding of og-pad-frame, so set one or the other.
col-start 7 / frame-end
<section class="og-grid [--og-columns:4] md:[--og-columns:12]">
  <img class="og-view md:og-frame" src="/cover.webp" alt="" />
  <p class="col-span-4 md:col-start-7 md:col-end-13">…</p>
</section>
og-view-start / col-end 8 + og-pad-frame-start

your turn

break out

Stay aligned, go wide.