Skip to content

The design language that makes your AI harness better at design.

JavaScript
7.4 KB
Raw Blame
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Line length: which characters are on the lines (browser-only)</title>
  <!--
    line-length divides an element's characters among its rendered lines, so
    the count has to be of the characters that rendered. textContent is not
    that: it holds an inline <style> child's CSS, the source's indentation,
    and one code unit for every combining mark (the unit tests pin marks; a
    script's glyph widths are too much the host font's business to assert in
    a browser). Each pass case here read as a long column on textContent and
    is a comfortable one on the page. Explicit pixel widths throughout.

    Every case has a plain twin on this page that renders the same characters
    on the same lines (plain-wide, plain-measure, flag-preserved), so a test
    can ask that each case reads the same as its twin whatever font the host
    browser resolves system-ui to.
  -->
  <style>
    body { font-family: system-ui, sans-serif; margin: 0; padding: 24px 40px; color: #1a1a1a; background: #fff; }
    h2 { font-size: 14px; line-height: 20px; margin: 32px 0 8px; color: #475569; }
    .copy { font-size: 16px; line-height: 24px; margin: 0; }
    .wide { width: 1000px; }
    .measure { width: 560px; }
    .keep { white-space: pre-wrap; }
    .cols { display: grid; grid-template-columns: 1000px 560px; gap: 40px; align-items: start; }
    .col > h2:first-of-type { margin-top: 0; }
  </style>
</head>
<body>
  <div class="cols">
    <div class="col" data-col="flag">
      <!-- FLAG: the count still charges real long columns -->
      <h2>Flag: a plain wide column, the twin of the next two</h2>
      <p class="copy wide plain-wide">Reading copy set across a column this wide asks the eye to travel a long way back to the start of every line, and after a few lines of it a reader starts to lose their place. The measure is what a designer sets with a max-width on the text block, and this block sets none at all, so every line runs the full width of the column it sits in from one edge to the other.</p>

      <h2>Flag: a wide column that also carries an inline style child</h2>
      <p class="copy wide flag-style-child"><style>.flag-style-child { min-height: 48px; }</style>Reading copy set across a column this wide asks the eye to travel a long way back to the start of every line, and after a few lines of it a reader starts to lose their place. The measure is what a designer sets with a max-width on the text block, and this block sets none at all, so every line runs the full width of the column it sits in from one edge to the other.</p>

      <h2>Flag: a wide column written with source indentation</h2>
      <p class="copy wide flag-indented">
                        Reading copy set across a column this wide asks the eye to travel a long way back to the start
                        of every line, and after a few lines of it a reader starts to lose their place. The measure is
                        what a designer sets with a max-width on the text block, and this block sets none at all, so
                        every line runs the full width of the column it sits in from one edge to the other.
      </p>

      <h2>Flag: preserved white space is on the line</h2>
      <!-- Under pre-wrap the runs of spaces render, so they are characters of
           the line and the column is as long as it looks. -->
      <p class="copy wide keep flag-preserved">Reading copy set across a column this wide asks the eye   to travel a long way back   to the start of every line,   and after a few lines of it   a reader starts to lose their place.   The measure is what a designer sets   with a max-width on the text block,   and this block sets none at all,   so every line runs the full width.</p>

      <h2>Flag: the same preserved white space in a span inside a normal paragraph</h2>
      <!-- Each text node keeps or folds its white space by the white-space it
           inherits, so this reads the same as the pre-wrap paragraph above. -->
      <p class="copy wide flag-preserved-nested">Reading copy set across a column this wide asks the eye<span class="keep">   to travel a long way back   to the start of every line,   and after a few lines of it   a reader starts to lose their place.   The measure is what a designer sets   with a max-width on the text block,   and this block sets none at all,   so every line runs the full width.</span></p>
    </div>

    <div class="col" data-col="pass">
      <!-- PASS: a comfortable measure that textContent overcounts -->
      <h2>Pass: a plain 560px measure, the twin of the next four</h2>
      <p class="copy measure plain-measure">A paragraph held to a comfortable measure wraps long before the eye has far to travel back, and this one keeps to about seventy characters a line.</p>

      <h2>Pass: a 560px measure with an inline style child</h2>
      <!-- directus.io's hero paragraph: a typewriter component ships its
           keyframes in a style element inside the paragraph. -->
      <p class="copy measure pass-style-child"><style>
    @keyframes pass-style-child-blink {
      0%, 50% { opacity: 1; }
      51%, 100% { opacity: 0; }
    }
    .pass-style-child { min-height: 48px; }
    @media (max-width: 768px) {
      .pass-style-child { min-height: 96px; }
    }
    .pass-style-child .cursor { animation: pass-style-child-blink 1s step-end infinite; }
    </style>A paragraph held to a comfortable measure wraps long before the eye has far to travel back, and this one keeps to about seventy characters a line.</p>

      <h2>Pass: a 560px measure with a hidden child and a script child</h2>
      <p class="copy measure pass-hidden-child">A paragraph held to a comfortable measure wraps long before the eye has far to travel back,<span style="display: none"> with a long run of words that a script reveals later and that take up no part of any line until then, however many of them there are in the source of the page,</span><script type="application/json">{"note": "data a component reads on hydration, which is text content and never a rendered character on any line of this paragraph"}</script> and this one keeps to about seventy characters a line.</p>

      <h2>Pass: a 560px measure with a content-visibility: hidden child</h2>
      <!-- The child's box lays out with no size and its text renders nowhere,
           so neither its characters nor any rect of its text is on a line. -->
      <p class="copy measure pass-cv-hidden">A paragraph held to a comfortable measure wraps long before the eye has far to travel back,<span style="display: inline-block; content-visibility: hidden"> with a long run of words that waits off screen for a reveal and takes up no part of any line until then, however many of them there are in the source,</span> and this one keeps to about seventy characters a line.</p>

      <h2>Pass: a 560px measure written with deep source indentation</h2>
      <!-- odishatreasury.gov.in: a template indents every wrapped source line. -->
      <p class="copy measure pass-indented">
                                            A paragraph held to a comfortable
                                            measure wraps long before the eye has
                                            far to travel back, and this one keeps
                                            to about seventy characters a line.
      </p>
    </div>
  </div>
</body>
</html>