# Code

A function name or a flag, inside a sentence.

- Group: Display
- Import: `import { Code } from '@misoto22/design'`
- Page: https://ui.misoto22.com/components/code/
- Related: code-block, kbd

## When to reach for it

Inline code within running text. A multi-line snippet is a CodeBlock.

## Anatomy

- **Chip** (required) — A real <code> on the --radius-sm corner, filled with --stone. Sized at 0.85em rather than in pixels, so the same token is proportionate in body copy, in a caption and in a table cell.

## Best practices

### Do

- Use it for anything the reader would type or the machine would read: a flag, a path, a function, an env var name. The mono face is the signal that the string is literal.
- Let it inherit its size. It is set in em on purpose — fixed at one pixel value, the identical token comes out three different sizes on one page depending on where it landed.

### Don’t

- Do not hand it a multi-line string. It keeps no whitespace and draws no plate, so the snippet collapses into one run — that is CodeBlock’s job.
- Do not style a <span> to look like this instead. The element is the whole point: a mono span reads identically and tells a screen reader nothing, and "pass dash dash force" is not what the sentence said.

## Accessibility

- Renders <code>, which is what tells assistive tech the run is literal rather than prose.

## Code

A function name, a flag, a filename — inside a sentence. Renders a `<code>`, which is the element that means this. A `<span>` in a mono face looks identical and tells a screen reader nothing, and "pass dash dash force" is not what the sentence said. Sized in `em` rather than in pixels, so the chip tracks whatever type it sits beside — the same rule `Kbd` follows, and for the same reason: fixed at one value, the identical token came out three different sizes on one page depending on whether it landed in body copy, a caption or a table cell. The block form is `CodeBlock`. This one is inline by construction: it draws no plate, keeps no whitespace, and a multi-line string handed to it collapses into one run.

### Props

- `children` (required) — `ReactNode`.

Also accepts: `HTMLAttributes<HTMLElement>`.

## Example — inline

```tsx
import { Code, Text } from '@misoto22/design'

<div className="flex flex-col gap-3">
  <Text>
    Pass <Code>--force</Code> to overwrite <Code>dist/</Code>, and read the
    merge helper in <Code>src/lib/cn.ts</Code>.
  </Text>
  <Text size="sm" tone="muted">
    At the small step it tracks down with the sentence: <Code>--force</Code>.
  </Text>
</div>
```

## Example — a literal or a key

```tsx
import { Code, Kbd, Text } from '@misoto22/design'

<div className="flex max-w-prose flex-col gap-3">
  <Text size="sm">
    Press <Kbd>⌘</Kbd> <Kbd>K</Kbd> to open the palette, then type{' '}
    <Code>Markdown</Code> to reach the component.
  </Text>
  <Text size="sm">
    The flag is <Code>--force</Code>; the key that cancels the run is <Kbd>Esc</Kbd>.
  </Text>
</div>
```

## Example — a list of flags

```tsx
import { Code } from '@misoto22/design'

<dl className="m-0 grid grid-cols-[auto_1fr] items-baseline gap-x-5 gap-y-2 text-sm text-(--ink-2)">
  <dt><Code>--force</Code></dt>
  <dd className="m-0">Overwrites <Code>dist/</Code> instead of failing on it.</dd>
  <dt><Code>--filter</Code></dt>
  <dd className="m-0">Runs in one workspace package.</dd>
  <dt><Code>--dry-run</Code></dt>
  <dd className="m-0">Prints what would be published, and publishes nothing.</dd>
</dl>
```
