UI library · Sample project

Set up a reading layout

Build one HTML page with a bounded line width and a consistent gap above its section headings.

Define the tokens

Create a file named guide.css and paste in these defaults. The width is measured in ch units, and the heading gap uses the root font size.

:root {
  --reading-measure: 68ch;
  --section-gap: 2rem;
}

Style the article

Append these rules to guide.css. The guide class limits the article width while allowing it to shrink on a small screen.

.guide { max-inline-size: var(--reading-measure); line-height: 1.65; }
.guide h2 { margin-block-start: var(--section-gap); }

Open the page

Save this example as index.html beside guide.css and open it in your browser.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Getting started</title>
  <link rel="stylesheet" href="guide.css">
</head>
<body>
  <article class="guide">
    <h1>Getting started</h1>
    <p>This guide walks you through setting up a local workspace, choosing a configuration, and running your first example.</p>
    <h2>Requirements</h2>
    <p>Begin with a text editor and a browser.</p>
  </article>
</body>
</html>

Compare the two widths

In a wide browser window, change --reading-measure from 68ch to 52ch and reload. The first paragraph should wrap sooner. The 2rem gap above Requirements stays the same. On a phone the available space may already be narrower than either limit.