All tools

Tool · Tampermonkey userscript

Responsive Layout Grid

Lays a configurable column grid over any live page, with its own settings for each breakpoint, to check that content lines up.

Written by
Rob Wood
Version
0.1.0
Licence
MIT
Runs on
Any site
Shortcut
Alt+Shift+G

Needs the free Tampermonkey extension for Chrome, Firefox, Edge or Safari. Install it first, then the script.

The script on this site's homepage at 1440px wide, set to the site's own grid of four columns with 4rem gutters in a 75rem container: the hero text sits in the first two columns and the photo fills the last two, both edges landing on the grid, and the script's panel lists the settings for its three breakpoints

The check

Building to the designer's grid

Designs made in Figma and similar tools sit on a column grid, but the browser doesn't show it. I wanted to set up the same grid the designer used over the live page, to get the build pixel-perfect. Used alongside Webpage Guidelines, it confirms that placements and measurements are what the designer intended.

Features

What it does

  • Columns per breakpoint

    Set columns, gutter, margin and max width for each min-width, like a stylesheet.

  • Any CSS length

    Gutters and margins take px, rem, vw, %, clamp() or calc(), just as the site defines them.

  • Follows the window

    The matching breakpoint switches in as you resize, and the panel shows which one is active.

  • Baseline grid

    Optional horizontal lines at any row height, scrolling with the text.

  • Your colours

    Pick the colour and opacity, and number the columns or not.

  • Saved per site

    Every site keeps its own grid.

How to use it

4 steps

  1. Step 1: Install Tampermonkey, then the script.

  2. Step 2: Open any page: the panel appears bottom left.

  3. Step 3: Enter the site's columns, gutters and margins for each breakpoint.

  4. Step 4: Press Alt+Shift+G to show or hide the grid.

Under the hood

How it's built

Plain JavaScript with no libraries, in about 330 lines, using only Tampermonkey's own storage. This is an early version, 0.1.0. It never changes the page's layout.

How it stays out of the page's way

The grid and the panel both live in a Shadow DOM root on a zero-sized, fixed host attached to <html>, so the page's CSS can't restyle them and theirs can't leak out. The host starts from all: initial and ignores the pointer, so the grid never blocks clicks on the page; only the panel takes them.

The browser does the maths

The overlay is a real CSS grid: repeat(n, minmax(0, 1fr)) columns, with the gutter as column-gap, the margin as padding and the max width centred. Because those are the same properties a site's own layout uses, any CSS length works and the columns land where the browser would put them.

Breakpoints like media queries

The active breakpoint is picked the way min-width media queries are: the largest min-width that fits the window wins. Each value is checked with CSS.supports() as you type, and an invalid one is marked and ignored rather than breaking the grid.

Baseline lines that scroll

The baseline grid is one repeating linear gradient. The overlay is fixed to the window, so its background position follows the scroll, keeping the lines on the text.

Remembered per site

Settings are saved with Tampermonkey's GM_setValue, keyed by site, since every site has its own grid. It skips iframes, so it only ever appears once.

  • Layout
  • Responsive design
  • Design QA
  • CSS Grid
  • Shadow DOM
Next tool Image Size Highlighter

All my userscripts, free and open source

Browse on GitHub