# Typography

`Text`, `Heading`, `Body` and `BodySmall` set text from the font, size, weight, line-height and color tokens. Each renders on the server. The element is chosen separately from the size, so the document outline stays correct whatever the visual design.

```tsx
import { Body, BodySmall, Heading, Text } from '@blocks/design-system'
```

## An article

**Example: Station guide** (`examples/typography/station-guide.tsx`)

```tsx
import { Body, BodySmall, Heading, Measure, Text } from '@blocks/design-system'

export default function StationGuide() {
  return (
    <Measure as="article" aria-labelledby="guide-title" marginX="none">
      <Heading as="h2" id="guide-title" fontSize="xl">
        Station guide
      </Heading>
      <Body>
        Each station reports snow depth, water content and temperature. Readings arrive hourly and are checked against
        nearby stations before they appear here.
      </Body>
      <Heading as="h3" fontSize="lg">
        Snow depth
      </Heading>
      <Body>
        Depth is measured by an ultrasonic sensor above a level board. <Text fontWeight="semibold">Sudden drops</Text>{' '}
        usually mean wind, not melt.
      </Body>
      <BodySmall color="text-muted">Sensor accuracy is about half an inch.</BodySmall>
      <Heading as="h3" fontSize="lg">
        Water content
      </Heading>
      <Body>Snow water equivalent is the depth of water the snowpack would make if it all melted at once.</Body>
    </Measure>
  )
}
```

## Text

`Text` is the base the others build on. It renders a `<span>` unless you pass `as`, and takes `fontSize`, `fontWeight`, `fontFamily`, `lineHeight` and `color` tokens plus margin props. Colors are semantic tokens such as `text-muted` and `danger-text`, which stay readable in both themes.

**Example: Text tokens** (`examples/typography/text-tokens.tsx`)

```tsx
import { Stack, Text } from '@blocks/design-system'

export default function TextTokens() {
  return (
    <Stack gap="xs">
      <Text fontSize="xl" fontWeight="bold">
        Storm total 18 in
      </Text>
      <Text color="text-muted">Since Tuesday evening</Text>
      <Text fontFamily="monospace" fontSize="sm">
        STN-651 · 05:00 UTC
      </Text>
      <Text color="danger-text" fontWeight="medium">
        Avalanche warning in effect
      </Text>
    </Stack>
  )
}
```

## Headings

`Heading` renders an `<h3>` in the heading font, size and weight unless you pass `as` (`h1`–`h6` or `span`). Pick the level for the outline and `fontSize` for the look. A `span` gives heading styling to text that should not appear in the outline. Themes change heading type through `--ds-font-heading`.

**Example: Levels and sizes** (`examples/typography/heading-levels.tsx`)

```tsx
import { Heading, Stack } from '@blocks/design-system'

export default function HeadingLevels() {
  return (
    <Stack gap="sm">
      <Heading as="h2" fontSize="lg">
        A second-level heading at the lg size
      </Heading>
      <Heading as="h3" fontSize="xxl">
        A third-level heading at the xxl size
      </Heading>
      <Heading as="span" fontSize="md" color="text-muted">
        A heading style on a span, outside the outline
      </Heading>
    </Stack>
  )
}
```

## Body text

`Body` is a paragraph at the `md` size and `BodySmall` one at `sm`, for captions, notes and secondary details. Pass `as="span"` for inline text.

## Props

**`Text` props**

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `as` | `ElementType` | — | The element or component to render, e.g. `as={NextLink}`. |
| `color` | `"text" \| "overlay" \| "bg" \| "bg-subtle" \| "surface" \| "surface-hover" \| "surface-active" \| "selected" \| "border-subtle" \| "border" \| "border-strong" \| "focus-ring" \| "accent" \| "accent-hover" \| "accent-fg" \| "accent-subtle" \| "accent-text" \| "danger" \| "danger-hover" \| "danger-fg" \| "danger-subtle" \| "danger-text" \| "warning" \| "warning-hover" \| "warning-fg" \| "warning-subtle" \| "warning-text" \| "success" \| "success-hover" \| "success-fg" \| "success-subtle" \| "success-text" \| "info" \| "info-hover" \| "info-fg" \| "info-subtle" \| "info-text" \| "text-muted"` | `text` | A color token. Defaults to `"text"`. |
| `fontFamily` | `"body" \| "heading" \| "monospace"` | — | A font token: `body`, `heading` or `monospace`. |
| `fontSize` | `"body" \| "code" \| "heading" \| "xxs" \| "xs" \| "sm" \| "md" \| "lg" \| "xl" \| "xxl" \| "xxxl" \| "xxxxl" \| "xxxxxl" \| "inherit"` | `body` | A font size token, e.g. `"sm"` or `"heading"`, or `"inherit"` to keep the parent's size. Defaults to `"body"`. |
| `fontWeight` | `"body" \| "heading" \| "medium" \| "bold" \| "semibold"` | — | A font weight token: `body`, `medium`, `semibold`, `heading` or `bold`. |
| `lineHeight` | `"body" \| "heading" \| "inherit"` | `body` | `body` or `heading`, or `"inherit"` to keep the parent's. Defaults to `"body"`. |

Also accepts [styling escape hatches](https://design-system.blocks-ui.com/components/box.md#escape-hatches) and [margin props](https://design-system.blocks-ui.com/components/box.md#spacing), and the native attributes of the element it renders.

**`Heading` props**

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `as` | `ElementType` | `h3` | A heading level from `"h1"` to `"h6"`, or `"span"`. Defaults to `"h3"`. |
| `color` | `"text" \| "overlay" \| "bg" \| "bg-subtle" \| "surface" \| "surface-hover" \| "surface-active" \| "selected" \| "border-subtle" \| "border" \| "border-strong" \| "focus-ring" \| "accent" \| "accent-hover" \| "accent-fg" \| "accent-subtle" \| "accent-text" \| "danger" \| "danger-hover" \| "danger-fg" \| "danger-subtle" \| "danger-text" \| "warning" \| "warning-hover" \| "warning-fg" \| "warning-subtle" \| "warning-text" \| "success" \| "success-hover" \| "success-fg" \| "success-subtle" \| "success-text" \| "info" \| "info-hover" \| "info-fg" \| "info-subtle" \| "info-text" \| "text-muted"` | — | A color token. Defaults to `"text"`. |
| `fontFamily` | `"body" \| "heading" \| "monospace"` | — | A font token: `body`, `heading` or `monospace`. |
| `fontSize` | `"body" \| "code" \| "heading" \| "xxs" \| "xs" \| "sm" \| "md" \| "lg" \| "xl" \| "xxl" \| "xxxl" \| "xxxxl" \| "xxxxxl" \| "inherit"` | — | A font size token, e.g. `"sm"` or `"heading"`, or `"inherit"` to keep the parent's size. Defaults to `"body"`. |
| `fontWeight` | `"body" \| "heading" \| "medium" \| "bold" \| "semibold"` | — | A font weight token: `body`, `medium`, `semibold`, `heading` or `bold`. |
| `lineHeight` | `"body" \| "heading" \| "inherit"` | — | `body` or `heading`, or `"inherit"` to keep the parent's. Defaults to `"body"`. |

Also accepts [styling escape hatches](https://design-system.blocks-ui.com/components/box.md#escape-hatches), [margin props](https://design-system.blocks-ui.com/components/box.md#spacing) and [a ref](https://design-system.blocks-ui.com/components/box.md#refs), and the native attributes of the element it renders.

**`Body` props**

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `as` | `ElementType` | `p` | `"p"` or `"span"`. Defaults to `"p"`. |
| `color` | `"text" \| "overlay" \| "bg" \| "bg-subtle" \| "surface" \| "surface-hover" \| "surface-active" \| "selected" \| "border-subtle" \| "border" \| "border-strong" \| "focus-ring" \| "accent" \| "accent-hover" \| "accent-fg" \| "accent-subtle" \| "accent-text" \| "danger" \| "danger-hover" \| "danger-fg" \| "danger-subtle" \| "danger-text" \| "warning" \| "warning-hover" \| "warning-fg" \| "warning-subtle" \| "warning-text" \| "success" \| "success-hover" \| "success-fg" \| "success-subtle" \| "success-text" \| "info" \| "info-hover" \| "info-fg" \| "info-subtle" \| "info-text" \| "text-muted"` | — | A color token. Defaults to `"text"`. |
| `fontFamily` | `"body" \| "heading" \| "monospace"` | — | A font token: `body`, `heading` or `monospace`. |
| `fontSize` | `"body" \| "code" \| "heading" \| "xxs" \| "xs" \| "sm" \| "md" \| "lg" \| "xl" \| "xxl" \| "xxxl" \| "xxxxl" \| "xxxxxl" \| "inherit"` | — | A font size token, e.g. `"sm"` or `"heading"`, or `"inherit"` to keep the parent's size. Defaults to `"body"`. |
| `fontWeight` | `"body" \| "heading" \| "medium" \| "bold" \| "semibold"` | — | A font weight token: `body`, `medium`, `semibold`, `heading` or `bold`. |
| `lineHeight` | `"body" \| "heading" \| "inherit"` | — | `body` or `heading`, or `"inherit"` to keep the parent's. Defaults to `"body"`. |

Also accepts [styling escape hatches](https://design-system.blocks-ui.com/components/box.md#escape-hatches), [margin props](https://design-system.blocks-ui.com/components/box.md#spacing) and [a ref](https://design-system.blocks-ui.com/components/box.md#refs), and the native attributes of the element it renders.

**`BodySmall` props**

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `as` | `ElementType` | `p` | `"p"` or `"span"`. Defaults to `"p"`. |
| `color` | `"text" \| "overlay" \| "bg" \| "bg-subtle" \| "surface" \| "surface-hover" \| "surface-active" \| "selected" \| "border-subtle" \| "border" \| "border-strong" \| "focus-ring" \| "accent" \| "accent-hover" \| "accent-fg" \| "accent-subtle" \| "accent-text" \| "danger" \| "danger-hover" \| "danger-fg" \| "danger-subtle" \| "danger-text" \| "warning" \| "warning-hover" \| "warning-fg" \| "warning-subtle" \| "warning-text" \| "success" \| "success-hover" \| "success-fg" \| "success-subtle" \| "success-text" \| "info" \| "info-hover" \| "info-fg" \| "info-subtle" \| "info-text" \| "text-muted"` | — | A color token. Defaults to `"text"`. |
| `fontFamily` | `"body" \| "heading" \| "monospace"` | — | A font token: `body`, `heading` or `monospace`. |
| `fontSize` | `"body" \| "code" \| "heading" \| "xxs" \| "xs" \| "sm" \| "md" \| "lg" \| "xl" \| "xxl" \| "xxxl" \| "xxxxl" \| "xxxxxl" \| "inherit"` | — | A font size token, e.g. `"sm"` or `"heading"`, or `"inherit"` to keep the parent's size. Defaults to `"body"`. |
| `fontWeight` | `"body" \| "heading" \| "medium" \| "bold" \| "semibold"` | — | A font weight token: `body`, `medium`, `semibold`, `heading` or `bold`. |
| `lineHeight` | `"body" \| "heading" \| "inherit"` | — | `body` or `heading`, or `"inherit"` to keep the parent's. Defaults to `"body"`. |

Also accepts [styling escape hatches](https://design-system.blocks-ui.com/components/box.md#escape-hatches), [margin props](https://design-system.blocks-ui.com/components/box.md#spacing) and [a ref](https://design-system.blocks-ui.com/components/box.md#refs), and the native attributes of the element it renders.

## Accessibility

- Use one `h1` per page and don’t skip levels: screen reader users move through a page by its headings.
- Don’t rely on color alone to carry meaning, as in the warning above, which also says “warning”.
- Sizes are rem-based tokens, so text grows with the reader’s font-size setting.
