# Typography

One sans family at three sizes, a monospace for what is copied, and numbers that line up.

API [Input](/ui/storybook/?path=/docs/ui-primitives-input--docs) [Card](/ui/storybook/?path=/docs/ui-primitives-card--docs) [Table](/ui/storybook/?path=/docs/ui-primitives-table--docs) [TextLink](/ui/storybook/?path=/docs/ui-primitives-textlink--docs) [InlineCode](/ui/storybook/?path=/docs/ui-primitives-inlinecode--docs)

**Set the interface in `text-ui`, step down to `text-ui-sm` for what is secondary and to `text-ui-xs` only for a badge, and up to `text-title` for a title.** Hierarchy comes from size, weight and the muted colour together, never from a fifth size.

```tsx
import { CI_RUN } from "@orz/fixtures/ci-run.ts";
import { PULL_REQUEST } from "@orz/fixtures/pull-request.ts";
import {
  Card,
  CardContent,
  CardHeader,
  CardTitle,
} from "@orz/ui/components/card";
import { InlineCode } from "@orz/ui/components/inline-code";
import {
  Table,
  TableBody,
  TableCell,
  TableHead,
  TableHeader,
  TableRow,
} from "@orz/ui/components/table";
import { Timestamp } from "@orz/ui/components/timestamp";
import { CircleCheckIcon, CircleXIcon } from "lucide-react";

const review = PULL_REQUEST.timeline.find(
  (event) => event.kind === "comment" && event.author === "claude-agent",
);
const paragraph =
  review?.kind === "comment"
    ? (review.body.split("\n\n")[0]?.replaceAll("\n", " ") ?? "")
    : "";

export function RunSummary() {
  return (
    <Card>
      <CardHeader>
        <CardTitle>
          {CI_RUN.workflow} #{CI_RUN.id}
        </CardTitle>
      </CardHeader>
      <CardContent className="grid gap-4">
        <div className="text-muted-foreground text-ui-sm">
          Started <Timestamp value={CI_RUN.startedAt} /> on{" "}
          <InlineCode>{CI_RUN.branch}</InlineCode> at{" "}
          <InlineCode>{CI_RUN.commit}</InlineCode>
        </div>
        <Table>
          <TableHeader>
            <TableRow>
              <TableHead>Job</TableHead>
              <TableHead>Status</TableHead>
              <TableHead className="text-right">Time (s)</TableHead>
            </TableRow>
          </TableHeader>
          <TableBody>
            {CI_RUN.jobs.map((job) => (
              <TableRow key={job.id}>
                <TableCell>{job.name}</TableCell>
                <TableCell>
                  <span className="flex items-center gap-1.5">
                    {job.status === "failed" ? (
                      <CircleXIcon className="size-4 text-destructive" />
                    ) : (
                      <CircleCheckIcon className="size-4 text-success" />
                    )}
                    {job.status === "failed" ? "Failed" : "Passed"}
                  </span>
                </TableCell>
                <TableCell className="text-right tabular-nums">
                  {job.duration}
                </TableCell>
              </TableRow>
            ))}
          </TableBody>
        </Table>
        <blockquote className="grid max-w-prose gap-1 text-ui leading-6">
          <p>
            {paragraph
              .split("`")
              .map((part, index) =>
                index % 2 === 1 ? (
                  <InlineCode key={part}>{part}</InlineCode>
                ) : (
                  part
                ),
              )}
          </p>
          <footer className="text-muted-foreground text-ui-sm">
            claude-agent, reviewing #{PULL_REQUEST.number}
          </footer>
        </blockquote>
      </CardContent>
    </Card>
  );
}
```

The pull request demo's CI run, at every row of the scale below: the run is the card's title, the jobs and the review are body text, the column headers and the reviewer are secondary, and the branch, the commit and `retryOnce` are monospace. The times line up because they are `tabular-nums`, and the review stops at a readable width however wide the card grows.

## The scale

| Role                                                                      | Classes                                                   | Size |
| ------------------------------------------------------------------------- | --------------------------------------------------------- | ---- |
| Body, labels, menu items, button text                                     | `text-ui`                                                 | 13px |
| A title: a dialog, a sheet or a page's panel                              | `font-heading text-title font-medium`                     | 15px |
| Secondary: a timestamp, a hint, table text, a module's name in its header | `text-ui-sm text-muted-foreground`                        | 12px |
| A count after a label: a row's, a segment's, a command's                  | `text-ui-sm text-muted-foreground tabular-nums`           | 12px |
| A badge, and nothing else                                                 | `text-ui-xs`                                              | 11px |
| What a user copies or compares: ids, hashes, paths, code                  | `font-mono` at the size around it, or `text-ui-sm` inline | —    |

Running text you write yourself, a docs page or a help topic, is prose and has a scale of its own, so a style can set it apart from the controls around it: `text-prose` for its paragraphs with `leading-prose` between their lines, `text-prose-sm` and `text-prose-xs` for what is secondary, `text-prose-lg` for a lead, `text-heading-3` to `text-heading-1` for its headings, and `text-display` for a headline. A link in it is a `TextLink`, in `text-link`, which is the text's own colour until a style's palette gives links one, and a name from code in a sentence an `InlineCode`. These docs are set in it; inside a tool, a panel's title is `text-title`. The components follow the same scale: `DialogTitle` and `SheetTitle` are `font-heading text-title font-medium`, a `CardTitle` is a module's name in its ruled header, `font-heading text-ui-sm font-semibold`, a `Badge` is `text-ui-xs`, and a count after a label is a part drawn as the scale says: `NavListCount` and `TreeCount` at a row's end, `SegmentedControlCount` and `ToolbarCount` in a segment or a command, those two in the label's own colour once it is pressed.

## Family

`--font-ui` is Atkinson Hyperlegible Next and `--font-mono` OpenMono, then the system's faces. Atkinson is drawn for legibility: the letters a glance confuses, 0 and O, I, l and 1, are made to differ. It is set at 105%, where its letters stand as tall and run as wide as the sizes and spacing around them were measured for. What it lacks of Latin, such as ĉ, ḍ, ŋ and IPA, the library's build fills in from Noto Sans, scaled and weighted to match. OpenMono draws every symbol, an arrow or a box-drawing line, one cell wide, and no ligatures, so `!==` reads as typed. Both slash the zero the same way, top left to bottom right, so a version reads alike in either face and neither zero looks like Ø.

`styles.css` leaves the fonts out so an app with its own pays nothing for them; `@orz/ui/fonts.css` loads Atkinson Hyperlegible Next for Latin, Noto Sans for Cyrillic, Devanagari, Greek and Vietnamese, and OpenMono for monospace Cyrillic, Greek, Latin and Vietnamese. A browser fetches a script's file only when a page draws its characters. Chinese, Japanese and Korean come from the page's language, after the style's own Latin face: `lang="zh-Hans"` names Noto Sans SC or Noto Sans CJK SC, then PingFang SC and Microsoft YaHei, `ja` Noto Sans JP or Noto Sans CJK JP, then Hiragino Sans and Yu Gothic, and so on. None of those is shipped, so the system's, or one your app loads, draws them; one family for every language would draw Chinese with Japanese glyph shapes. `font-sans` and `--font-heading` are the same family; override `--font-heading` only if your app has a display face.

## Weight

`font-medium` marks a title or a label, the heading over a group of a menu's or a list's rows among them; `font-semibold` is for a page heading and a card's title. Body text stays regular. Bold inside a paragraph is for the one phrase a skimming reader must not miss, at most once or twice per screen.

## Numbers

Numbers that sit in a column, tick in place, or are compared across rows take `tabular-nums`, so every digit is the same width and a column of sizes lines up on the decimal point. The base layer already gives every `<time>` element `tabular-nums`; a date or time you render belongs in one, which `Timestamp` draws, and `TimestampRange` sets a span in them too (see [Writing](/ui/guidelines/content/writing/index.md)).

**Do**

Set compared numbers in `tabular-nums`, right-aligned, with the same number of decimals.

**Don't**

Leave proportional digits in a column, or vary the decimals or the units, so the eye has to read every value to compare two.

## Line length and truncation

Prose sits in at most about 75 characters a line ([Baymard Institute](https://baymard.com/blog/line-length-readability)), with `max-w-prose`, or `max-w-3xl` for a page. A single-line label that may be long takes `truncate` (or `min-w-0` on the flex child that holds it, or it never shrinks); the full text stays reachable somewhere other than a hover, because a `title` tooltip does not exist on a touchscreen. A long unbroken string in a block, such as a URL or a hash, takes `break-words` so it cannot push the layout sideways.

```tsx
import { INBOX_PEOPLE, INBOX_THREADS } from "@orz/fixtures/inbox.ts";
import { List, ListItem } from "@orz/ui/components/list";
import { useState } from "react";

const THREADS = ["flaky-retry", "docs-search", "touch-sizes"].flatMap(
  (id) => INBOX_THREADS.find((thread) => thread.id === id) ?? [],
);

export function TruncatedSubjects() {
  const [open, setOpen] = useState(THREADS[0]?.id);
  const thread = THREADS.find(({ id }) => id === open);
  return (
    <div className="grid gap-4 sm:grid-cols-[14rem_1fr]">
      <List purpose="listbox" className="min-w-0">
        <ul aria-label="Conversations">
          {THREADS.map(({ id, subject, messages }) => (
            <li key={id}>
              <ListItem current={id === open} asChild>
                <button
                  type="button"
                  aria-current={id === open ? "true" : undefined}
                  onClick={() => setOpen(id)}
                  className="flex min-h-row w-full items-baseline gap-2 px-3 py-2 text-left text-ui"
                >
                  <span className="min-w-0 flex-1 truncate">{subject}</span>
                  <span className="text-muted-foreground text-ui-sm">
                    {messages.length}
                  </span>
                </button>
              </ListItem>
            </li>
          ))}
        </ul>
      </List>
      {thread && (
        <article className="grid content-start gap-1">
          <h3 className="break-words font-heading font-medium text-prose">
            {thread.subject}
          </h3>
          <p className="text-muted-foreground text-ui-sm">
            {[
              ...new Set(
                thread.messages.map(({ from }) => INBOX_PEOPLE[from] ?? from),
              ),
            ].join(", ")}
          </p>
        </article>
      )}
    </div>
  );
}
```

The Mail demo's subjects, cut to one line in the list. Pick one and the heading beside the list shows it whole, wrapping where it has to: the full text is a click or a tap away, not a hover.

## On each platform

- **Pointer.** Inputs are `md:text-ui`, the body size.
- **Touch.** An `Input`, `Textarea` and `HighlightedInput` are `text-base` below `md`, and on a coarse pointer at every width, because a tablet is wider than `md`. iOS Safari zooms the page into any field whose text is under 16px when it takes focus ([how Safari decides](https://thingsthemselves.com/no-input-zoom-in-safari-on-iphone-the-pixel-perfect-way/)), and does not zoom back out. Keep that in any field you build: `text-base md:text-ui touch:text-base`.
- **Both.** Sizes are in `rem`, so a reader who raises the browser's text size gets larger text everywhere. Text must survive 200% without loss ([WCAG 1.4.4](https://www.w3.org/WAI/WCAG22/Understanding/resize-text.html)); do not set a fixed height on a box that holds text.

## In the demos

- [Notes](/ui/demos/notes/index.md): The preview holds a note to a readable measure. Titles truncate in the list, and its dates are set in tabular figures.
- [Pull request](/ui/demos/pull-request/index.md): Hashes, branches and logs are monospaced, durations and counts are tabular, and a commit subject truncates rather than wrapping its row.
