basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    White space in CSS: column width, line height and spacing line by line

    White space is spacing that shows what belongs with what: a line closer to its line, a paragraph to its heading, a group set apart from another group. Here’s the CSS for long-form text line by line: size, line height, column width, spacing around headings, paragraphs and lists, line wrapping.

    Where the numbers come from

    Guidelines for long text on screen:

    What Value Source
    Line length 45–75 characters, ideally around 66 Robert Bringhurst, “The Elements of Typographic Style”
    45–90 characters Matthew Butterick, “Practical Typography”
    no more than 80 characters WCAG 2.2, criterion 1.4.8 (level AAA)
    Line height 120–145% of the font size Butterick
    at least 1.5 within a paragraph WCAG 1.4.8
    Between paragraphs 1.5 times the line spacing WCAG 1.4.8

    Butterick’s line height is tighter: the rule comes from print. On screen lines are often longer, and the eye needs more room so it doesn’t jump a line on the way back to the left edge — which is why sites usually use 1.5–1.7.

    The file

    src/styles/prose.css
    .prose {
      font-size: 17px;
      line-height: 1.7;
    }

    17 px is one pixel above the browser default. In px the size follows page zoom but not the browser’s font size setting; 1.0625rem would give the same 17 px and respect it. A line height of 1.7 is at the upper end because the line is long, about 76 characters. The longer the line, the more line height it needs.

    default:font-size 16pxline-height normal

    .prose > p,
    .prose > ul,
    .prose > ol,
    .prose > blockquote {
      max-width: 42em;
    }
    Key part

    The column width belongs to the text, not the page: code and tables go full width. 42em at 17 px is 714 px — measured at 76–80 characters of Russian text on average, the upper end1. 38em would give about 69.

    .prose h2 {
      margin: 1.9em 0 0.6em;
      font-size: clamp(21px, 2.2vw, 27px);
      line-height: 1.2;
    }
    
    .prose h3 {
      margin: 1.5em 0 0.5em;
      font-size: 19px;
      line-height: 1.3;
    }
    Key part

    The space above a heading is three times the space below: the heading is held close to its text and set apart from the previous one. That’s the law of proximity — things next to each other read as one. The heading’s line height is 1.2: at a large size, 1.7 would split a two-line heading into two separate ones.

    .prose p,
    .prose ul,
    .prose ol,
    .prose table,
    .prose pre {
      margin: 0 0 1.1em;
    }

    1.1em between paragraphs — more than the gap between lines (0.7em) but less than the space above a heading. Three steps of spacing: line < paragraph < section. Spacing only at the bottom, so neighbours’ margins don’t add up or fight.

    default:margin 1em 0

    .prose li + li {
      margin-top: 0.3em;
    }
    
    .prose li::marker {
      color: var(--ink-3);
    }

    List items sit closer together than paragraphs: 0.3em against 1.1em. The list reads as one group rather than five separate paragraphs with dots. The marker is in the third text color: it’s there to find where an item starts, not to be read.

    h1, h2, h3 {
      text-wrap: balance;
    }
    
    p {
      text-wrap: pretty;
    }

    balance evens out a heading’s lines: instead of a long first line and one word on the second, two equal lines. Chromium balances blocks of up to 6 lines, Firefox up to 10; longer ones wrap as usual. pretty doesn’t leave a single word on a paragraph’s last line. A browser that doesn’t know these values skips the line.

    default wrap

    .prose p {
      hyphens: auto;
    }

    Automatic hyphenation is off on this site. It only works if the page declares its language (lang) and the browser has a dictionary for it. It’s off because the text is left-aligned: a ragged right edge without hyphenation leaves no gaps between words, so it doesn’t need hyphens (Left-aligned).

    default manual

    Spacing in an interface

    Text spacing is in em: it grows with the font size. Interfaces — cards, buttons, fields — use a pixel scale: 4, 8, 12, 16, 24, 32, 48 px. The rule is the same as for text: spacing inside a group is smaller than between groups. A card with 20 px of padding inside and 12 px between cards falls apart — neighbouring cards’ content ends up closer to each other than to their own headings.

    How to check

    • Zoom the page to 200% (Ctrl + +): text reflows, nothing is cut off or overlapping, and there’s no horizontal scrolling (WCAG 1.4.4 and 1.4.10).
    • Apply the WCAG 1.4.12 settings with an extension or a bookmarklet: line height 1.5, paragraphs 2em apart, letter spacing 0.12em, word spacing 0.16em. Text must not spill out of its boxes.
    • Device mode in DevTools at 360 px wide: no paragraph longer than the screen, no heading broken into one word per line.

    If it doesn’t work

    A section heading seems to hang between two paragraphs

    Cause
    The spacing above and below the heading is the same — it doesn’t tell which text the heading belongs to.
    Fix
    Make the space above the heading 2–3 times the space below: margin: 1.9em 0 0.6em.

    Set max-width: 65ch, and the line came out longer than expected

    Cause
    1ch is the width of the digit “0”, which is wider than an average letter: in Golos 17px 1ch is 10.55 px, while the average character of Russian text is 9.36 px. 65ch holds about 73 characters of it.
    Fix
    Pick the width by measuring your own font in your own language, and treat ch as approximate.

    The last line of a paragraph is a single short word

    Cause
    The browser wraps greedily: it fills the line and doesn’t look at what’s left for the end.
    Fix
    text-wrap: pretty on paragraphs — where it isn’t supported, the browser skips it.

    At 200% zoom, text spills out of its boxes

    Cause
    Box heights are set in pixels while the text size grows.
    Fix
    Spacing in em, no fixed heights on boxes with text; check with Ctrl + + up to 200%.

    Not verified yet

    1. characters per line of English text at 42em in Golos 17px ↑