# Code

> Code in a sentence, or a block of it on its own plate.

| | |
|---|---|
| Kind | component |
| Contract | `review` · [code.contract.yaml](https://github.com/Runceanu/rost/blob/master/contracts/code.contract.yaml) |
| Guidance | `proposed` |
| Source | [Figma 705:104](https://www.figma.com/design/1Zy0wiWKXQAvsfDBX3KR0d/UI-Kit-v01?node-id=705-104) · read 2026-11-04 · frozen 2026-11-04 |
| Implemented in | nowhere yet |

## Install

It lands in `src/rost/code/`, with what it needs and its contract:

```sh
npx github:Runceanu/rost add code
```

Then import `src/rost/fonts.css` and `src/rost/tokens.css` once, at the root of the app. More on this in [Install](https://rost.build/docs/install.md).

## Props

| Prop | Type | Values | Default |
|---|---|---|---|
| `block` | boolean |  | `false` |
| `html` | string |  |  |
| `children` | slot |  |  |

## Anatomy

- `root`: A `<code>`, or for a block a `<pre>` with the `<code>` inside.
- `text`: The `<code>` inside a block.

## When to use

- **A name in a sentence.** A prop, a token path or a file name inside running text: `tone=quiet`, `contracts/link.contract.yaml`.
- **What to write.** A few lines someone will copy. Coloured by a highlighter, or plain.

## When not to use

- **Emphasis.** Making a word stand out. Code means the word is exactly what you type.
- **Very long files.** A whole file on a page. Show the part that matters, and link to the rest.

## Behaviour

In a sentence it's the mono family at a slightly smaller size, with no plate, so a line full of token paths stays calm. A block gets the secondary plate, 16px inside and 12px corners, and scrolls sideways rather than wrapping.

The colours inside a block come from the highlighter, not from Rost. On the Rost site that's Shiki's vesper in dark and GitHub's high-contrast theme in light, with the comment greys made solid, so every word is 4.5:1 on the plate. Syntax colours as tokens would be the next step, and I haven't needed them in an app yet.

## Accessibility

- **Element**: `<code>`, and `<pre>` around it for a block, so a screen reader keeps the spacing.
- **Keyboard**: A block that scrolls gets `tabindex="0"`, so it can be scrolled without a mouse.

## Content

Exactly what someone types. No ellipsis inside a line they'd copy.

## Tokens

Every token this component uses, across all its variants.

| Token | Resolves to |
|---|---|
| `non-interactive/background/secondary` | `#171717` |
| `non-interactive/foreground/primary` | `#ededed` |
| `spacing/gap/medium` | `16px` |
| `spacing/radius/medium` | `12px` |
| `typography/label/font-size` | `12px` |
| `typography/line-height/20` | `20px` |

## No token, on purpose

| Part | Property | Value | Why |
|---|---|---|---|
| `root` | `font-family` | `'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace` | Rost has no mono family token yet. Where JetBrains Mono isn't loaded, the system mono stands in. |
| `root` | `font-size` | `0.88em` | In a sentence it follows the text around it. Mono looks bigger than General Sans at the same size, so a little smaller. |

See it live, with every value of every variant: [rost.build/components/code/](https://rost.build/components/code/)
