# Kbd

A key on a keyboard, set as one.

- Group: Display
- Import: `import { Kbd } from '@misoto22/design'`
- Page: https://ui.misoto22.com/components/kbd/
- Related: badge

## Anatomy

- **Key** (required) — The <kbd>: a --rule-2 hairline on the --radius-sm corner, min-w-[1.6em] so a single character is a cap rather than a sliver, and 0.8em type so the whole cap scales with the copy around it.
- **Legend** (required) — children, printed verbatim. One key per element — the space between two of them is a real space in the markup, not a separator the component draws.

## Best practices

### Do

- Write one Kbd per key. A whole chord in one box — ⌘K — is a single cap with two glyphs in it, and the min-w-[1.6em] that makes one character square just stretches to hold both.
- Let it take its size from its surroundings: it is set in em, so the same shortcut printed in a heading and in body copy comes out right in both. Pinning it to px is how one shortcut ended up three sizes on one page.
- Give a glyph-only key an aria-label — ⌘, ⌥ and ⇧ are read out as their Unicode names or skipped entirely, so a Mac shortcut written in symbols alone is a silent instruction.

### Don’t

- An outline Badge and a Kbd are near enough identical on screen, so the choice between them is entirely about meaning: <kbd> says the reader presses this, and a badge shaped like a key invites a press nothing answers.
- Nothing here binds anything. The element is typography, so a key printed for a shortcut no handler listens for is documentation of a feature the page does not have.

## Accessibility

- Renders <kbd>, which carries the meaning a styled <span> does not.

## Kbd

A key on a keyboard, set as one. Renders a `<kbd>`, which is the element that means this — a `<span>` styled to look like a key tells a screen reader nothing. Sized in `em` so it tracks whatever type it sits beside rather than fixing itself at one px value, which is how the same shortcut ended up three different sizes across a page.

### Props

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

Also accepts: `HTMLAttributes<HTMLElement>`.

## Example — default

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

<p className="m-0 text-sm text-(--ink-2)">
  Press <Kbd>⌘</Kbd> <Kbd>K</Kbd> to open the palette, or <Kbd>Esc</Kbd> to close it.
</p>
```

## Example — one cap per key

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

<div className="flex flex-col gap-3">
  <Text size="sm">
    Reformat the file with <Kbd aria-label="Command">⌘</Kbd>{' '}
    <Kbd aria-label="Shift">⇧</Kbd> <Kbd>P</Kbd>.
  </Text>
  <Text size="sm">
    On Windows and Linux the same chord is <Kbd>Ctrl</Kbd> <Kbd>Shift</Kbd> <Kbd>P</Kbd>.
  </Text>
</div>
```

## Example — sized by its copy

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

<div className="flex flex-col gap-4">
  <Heading level={3}>
    Press <Kbd>/</Kbd> to search
  </Heading>
  <Text>
    The same <Kbd>/</Kbd> works from anywhere on the page.
  </Text>
  <Text size="xs" tone="muted">
    Shortcut: <Kbd>/</Kbd>
  </Text>
</div>
```
