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.
get started
npm install outgridunder half a kilobyte, minified and gzipped
view on npm/* plain CSS */
@import "outgrid";
/* Tailwind CSS v4 */
@import "tailwindcss";
@import "outgrid/tailwind";The idea
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.
md:og-view.Breakouts
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.
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.
<section class="og-grid">
<div class="og-view">…</div>
</section>Frame padding
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.
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.
<section class="og-grid">
<div class="og-view og-pad-frame">…</div>
</section>Subgrid
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.
- Its children are placed on the columns of the parent grid, with its gutter.
col-start 3,frame-endand the other lines keep their names. - Breakouts work inside it:
og-view,og-view-startandog-view-endstill reach the edges of the screen. - The rows are its own, spaced by
--og-gutter-yas inog-grid. - Give it its own
grid-columnand it can be narrower than the frame: its children use the columns it spans.
<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
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.
--og-columnsdefault 12Number of columns.
--og-max-widthdefault 80remWidth of the frame, without the padding.
--og-paddingdefault 1remSpace 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-gridcomputes it again on itself, so a width or a padding set on a grid reaches its breakouts.
:root {
--og-max-width: 72rem;
--og-padding: clamp(1rem, 4vw, 3rem);
}
@media (width < 48rem) {
:root {
--og-columns: 4;
}
}Tailwind CSS
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.
- 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-6beats the padding ofog-pad-frame, so set one or the other.
<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>your turn
break out
Stay aligned, go wide.