A modular type scale, a grid, and the contrast of two colors

Design and typography

Every pair of greys, type against ground, darker pairs at the foot. Each heavier curve is one more step of 3/2, the default scale ratio, in contrast. Dots mark the pairs of sixteen greys that pass at 4.5. Malachite is black on white, exactly 21.

A modular step is an exact rational power of a ratio greater than one. Grid width is columns times track, plus the gutters between them. Contrast follows the sRGB relative-luminance note in WCAG 2.2: the power 2.4 is enclosed by rationals, and black on white is the exact ratio 21. The page does not certify a whole page.

Four squares for the type sizes 32/3, 16, 24, and 36, and a grid of four 64-pixel tracks with three 16-pixel gutters.
The default scale at one and a half times size. Above, squares whose sides are the four sizes, 32/3, 16, 24, and 36 pixels, steps -1 to 2 of the ratio 3/2 on a base of 16. Below, the 304-pixel grid: four 64-pixel tracks with three dashed 16-pixel gutters.

The ratio must be greater than one. Steps run from -4 to 6 and span at most eight steps. Colors are six hexadecimal digits. The default pair is black on white.

The result appears here when the page script runs.

How it is computed

Method

Sizes are base times the ratio to an integer power, as a reduced rational. Width is an integer. For a channel at most 10, relative luminance uses the linear branch as an exact rational. Above that, the power 12/5 is enclosed by searching a denominator of one million. Coefficients 0.2126, 0.7152, and 0.0722 are the exact decimals 1063/5000, 447/625, and 361/5000. Contrast adds 1/20 before dividing.

Assumptions

The enclosure can be wider than a float. A threshold is met only when the lower end clears it, missed only when the upper end falls short, and otherwise inconclusive. Anti-aliasing is not modelled.

Limits

Two colors are not a page, so the result says nothing about WCAG conformance for this site.

Reproducibility

The inputs are kept in the address bar, so the same link reruns the same calculation.