<!-- index: /slotted/llms.txt -->
# kbd

`data-ui="kbd"` · Keyboard key or shortcut.

## Import

```tsx
import { Kbd, KbdDefaultsProvider, Shortcut } from '@slotted/react';
```

## Minimal example

Example

```tsx
import { Inline } from '@slotted/react/inline';
import { Shortcut } from '@slotted/react/kbd';
import { Text } from '@slotted/react/typography';

export default function KbdBasic() {
  return (
    <Inline gap={3} align="center">
      <Text>Search orders</Text>
      <Shortcut keys="mod+k" />
    </Inline>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | kbd | yes |
| `legend` | span | yes |
| `name` | span | no |
| `shortcut` | kbd | no |
| `separator` | span | no |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `keyName` | `string` | — | Kbd | A token from the vocabulary — mod, meta, ctrl, alt, shift, fn, enter, escape, tab, space, backspace, delete, capslock, pageup, pagedown, home, end, plus, up, down, left, right — or an alias such as cmd, option, esc or arrowup. Wins over children where both are written. |
| `keys` | `string` | — | Shortcut | The whole combination: + joins keys pressed together, whitespace joins the steps of a sequence. |
| `platform` | `'auto' \| 'mac' \| 'windows' \| 'linux' \| 'other'` | auto | Kbd, Shortcut | Which keyboard the legends are drawn for. auto reads the browser; state it where the page is server-rendered. |
| `size` | `'xs' \| 'sm' \| 'md' \| 'lg' \| 'inherit'` | md | Kbd, Shortcut | xs to lg are fixed heights of 16, 20, 24 and 28 pixels whose legend answers density; inherit reads the text around the key and stays inside its line. |
| `variant` | `'raised' \| 'outline' \| 'soft' \| 'plain'` | raised | Kbd, Shortcut | raised is a key with a bottom edge, outline owns no ground, soft is the tinted chip, plain takes the color of the text it sits in. |
| `disabled` | `boolean` | false | Kbd, Shortcut | Dims the key without writing aria-disabled, which kbd may not carry. The item the shortcut belongs to owns the semantics. |
| `separator` | `string` | + | Shortcut | Between two simultaneous keys. A Mac joins with nothing whatever this says. |
| `messages` | `PartialMessages<KeysMessages>` | — | Kbd, Shortcut | Words laid over the keys catalog of the language in force, key by key: legends.*, names.*, and then — the word between two steps of a sequence, read aloud. |
| `legends` | `Record<string, string>` | — | Shortcut | Replaces what the eye sees, per key token: { mod: "Control" }. Falls back to the provider. |
| `names` | `Record<string, string>` | — | Shortcut | Replaces what a reader hears, per key token: { delete: "Remove" }. Falls back to the provider. |
| `children` | `ReactNode` | — | Kbd | The legend written verbatim — the application’s own word, neither resolved nor given a hidden name. |
| `children` | `ReactNode` | — | Shortcut | Keys authored one by one. They are rendered in the order written, which is the way out of the platform reordering. |
| `render` | `(props: KbdRootProps) => ReactNode` | — | Kbd, Shortcut | Substitutes the rendered element. Every data attribute and every part are handed to it. |
| `ref` | `Ref<HTMLElement>` | — | Kbd, Shortcut | Reaches the kbd element. There is no imperative handle beyond it: Kbd has no action a page cannot express declaratively. |
| `KbdDefaultsProvider` | `{ platform, size, variant, separator, legends, names }` | — | a subtree | Sets all six once for everything below it; an explicit prop on a key still wins. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `size` | `xs`, `sm`, `md`, `lg`, `inherit` | `md` |
| `variant` | `raised`, `outline`, `soft`, `plain` | `raised` |
| `platform` | `auto`, `mac`, `windows`, `linux`, `other` | `auto` |

## Rules

- There is no kbd pattern in the WAI-ARIA Authoring Practices — the pattern index carries no entry — and ARIA in HTML (W3C Recommendation, 11 August 2026) maps the kbd element to no corresponding role and declares it Naming Prohibited. Kbd therefore writes no role, no aria-label and no aria-disabled, and every word a reader hears is content.
- A key in the vocabulary hides its legend with aria-hidden and carries the word in a name part that Kbd clips from view itself. ⌘ is U+2318 PLACE OF INTEREST SIGN and would otherwise be read as one; Ctrl is an abbreviation whose pronunciation belongs to the screen reader’s dictionary. Both are announced “Control” or “Command” here.
- The plus between two keys is aria-hidden — it is punctuation joining two caps, and “Command Shift K” is what the operating systems announce for the same shortcut. The word between two steps of a sequence is not hidden, because it is the only thing that distinguishes “G then I” from “G and I together”.
- Nothing here is focusable and nothing here binds a key. WCAG 2.2 2.1.4 Character Key Shortcuts belongs to whoever registers the shortcut, because only the application knows whether a single-character shortcut can be turned off.
- The keys inside a combination keep their left-to-right order in a right-to-left document. A combination is one formula, the bidi algorithm renders the same string as one left-to-right run inside an Arabic paragraph, and a mirrored K + ⌘ is a shortcut no operating system displays. The combination as a whole still sits where the paragraph puts it.
- An arrow legend is never mirrored: ← is the physical Left arrow key, not a direction of travel.
- A key label is never truncated. A shortcut too wide for its column wraps between caps and never inside one, because half a key name is a wrong instruction where a wrapped shortcut is only a taller row.
- The legends and the spoken names are both replaceable, per application through the provider and per shortcut through legends and names, so one wording is one decision rather than one per shortcut.

## Tokens

`--slotted-border-strong`, `--slotted-border-width-thick`, `--slotted-border-width-thin`, `--slotted-control-border-color`, `--slotted-control-font-family`, `--slotted-control-font-size-lg`, `--slotted-control-font-size-md`, `--slotted-control-font-size-sm`, `--slotted-control-inner-size`, `--slotted-control-transition-duration`, `--slotted-control-transition-easing`, `--slotted-disabled-background`, `--slotted-disabled-border`, `--slotted-disabled-foreground`, `--slotted-font-family-sans`, `--slotted-font-weight-medium`, `--slotted-kbd-base-width`, `--slotted-kbd-border-color`, `--slotted-kbd-border-width`, `--slotted-kbd-color`, `--slotted-kbd-font-family`, `--slotted-kbd-font-weight`, `--slotted-kbd-radius`, `--slotted-kbd-surface`, `--slotted-kbd-symbol-font-family`, `--slotted-radius-lg`, `--slotted-radius-md`, `--slotted-radius-sm`, `--slotted-space-1`, `--slotted-space-2`, `--slotted-space-3`, `--slotted-space-4`, `--slotted-space-6`, `--slotted-space-7`, `--slotted-space-8`, `--slotted-surface-raised`, `--slotted-text`, `--slotted-text-box-edge`, `--slotted-text-muted`, `--slotted-tone-secondary-border`, `--slotted-tone-secondary-surface`, `--slotted-tone-secondary-text`

## Examples

### Playground

One key with every axis on it, driven by the controls below the canvas. Change platform and watch the legend change without the markup changing.

Excerpt — not a complete module

```tsx
<Kbd keyName="mod" />;

// Or a word outside the vocabulary.
<Kbd>Any key</Kbd>;
```

### How the key is painted

raised is the only value that looks like an object; outline owns no ground, so it survives on a solid surface where raised would cut a white hole.

Example

```tsx
import { Inline } from '@slotted/react/inline';
import { Shortcut } from '@slotted/react/kbd';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function KbdVariants() {
  return (
    <Stack gap={3}>
      <Inline justify="between" align="center">
        <Text>raised</Text>
        <Shortcut keys="mod+b" variant="raised" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>outline</Text>
        <Shortcut keys="mod+b" variant="outline" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>soft</Text>
        <Shortcut keys="mod+b" variant="soft" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>plain</Text>
        <Shortcut keys="mod+b" variant="plain" />
      </Inline>
    </Stack>
  );
}
```

### How large the key is

Four absolute heights, 16, 20, 24 and 28 pixels, that no legend and no variant changes; the legend reads the control type scale, so it shrinks with density inside the same box. xs fits a caption or a tooltip. inherit reads the text around it and stays inside its line, which is the step a heading and a footnote both need.

Example

```tsx
import { Inline } from '@slotted/react/inline';
import { Kbd } from '@slotted/react/kbd';
import { Stack } from '@slotted/react/stack';
import { Heading, Text } from '@slotted/react/typography';

export default function KbdSizes() {
  return (
    <Stack gap={4}>
      <Inline gap={3} align="center">
        <Kbd keyName="escape" size="xs" />
        <Kbd keyName="escape" size="sm" />
        <Kbd keyName="escape" size="md" />
        <Kbd keyName="escape" size="lg" />
      </Inline>
      <Heading level={3} size="md">
        Press <Kbd keyName="escape" size="inherit" /> to cancel the count
      </Heading>
      <Text size="sm">
        Press <Kbd keyName="escape" size="inherit" /> to discard the draft.
      </Text>
    </Stack>
  );
}
```

### A whole combination

One kbd nested inside another, which is what the HTML Standard says a combination is. The plus is a part of its own, so an application can restyle or replace it.

Excerpt — not a complete module

```tsx
<Shortcut keys="mod+shift+p" />;
```

### The same string on three keyboards

The modifiers are reordered into each platform’s own convention and the legends redrawn; on a Mac the separator is not rendered at all, because a Mac joins with nothing.

Example

```tsx
import { Inline } from '@slotted/react/inline';
import { Shortcut } from '@slotted/react/kbd';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function KbdPlatform() {
  return (
    <Stack gap={3}>
      <Inline justify="between" align="center">
        <Text>mac</Text>
        <Shortcut keys="meta+shift+s" platform="mac" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>windows</Text>
        <Shortcut keys="meta+shift+s" platform="windows" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>linux</Text>
        <Shortcut keys="meta+shift+s" platform="linux" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>other</Text>
        <Shortcut keys="meta+shift+s" platform="other" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>auto</Text>
        <Shortcut keys="meta+shift+s" platform="auto" />
      </Inline>
    </Stack>
  );
}
```

### One key after another

Whitespace between two groups is a step break, so “g i” is G then I. The word is read aloud where the plus is not, because it is the only thing that tells a sequence from a chord.

Example

```tsx
import { Inline } from '@slotted/react/inline';
import { Shortcut } from '@slotted/react/kbd';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function KbdSequence() {
  return (
    <Stack gap={3}>
      <Inline justify="between" align="center">
        <Text>Go to the inbox</Text>
        <Shortcut keys="g i" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>Go to orders</Text>
        <Shortcut keys="g o" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>Shortcuts</Text>
        <Shortcut keys="mod+k mod+s" />
      </Inline>
    </Stack>
  );
}
```

### Where a shortcut actually lives

A menu, where the label takes the room and the shortcut takes the end of the row. plain inherits the row’s color, so a row that dims dims its shortcut with no state to set.

Excerpt — not a complete module

```tsx
<li>
  <span>Open command palette</span>
  <Shortcut keys="mod+k" variant="plain" />
</li>;
```

### Available and unavailable

disabled dims the ground, the rim and the ink, and writes no aria-disabled: kbd may carry only the global ARIA attributes, so the item owns the semantics.

Example

```tsx
import { Inline } from '@slotted/react/inline';
import { Kbd, Shortcut } from '@slotted/react/kbd';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function KbdStates() {
  return (
    <Stack gap={3}>
      <Inline justify="between" align="center">
        <Text>Approve payment run</Text>
        <Shortcut keys="mod+enter" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>Reverse posting</Text>
        <Shortcut disabled keys="mod+shift+r" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>Dispatch to carrier</Text>
        <Kbd disabled keyName="enter" />
      </Inline>
    </Stack>
  );
}
```

### Content the application chose

The longest real key name, a legend replaced through the provider, and a four-key combination in a 320-pixel column: it wraps between caps and never inside one.

Excerpt — not a complete module

```tsx
<KbdDefaultsProvider
  legends={{ mod: 'Control', delete: 'Delete' }}
  names={{ delete: 'Remove' }}
  platform="windows"
>
  <Shortcut keys="mod+shift+delete" />
</KbdDefaultsProvider>;
```

### Composition and escape hatches

Keys written by hand are rendered in the order written, which is the way out of the platform reordering. render substitutes the element, and the provider decides for a whole application.

Example

```tsx
import { Inline } from '@slotted/react/inline';
import { Kbd, Shortcut } from '@slotted/react/kbd';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function KbdComposition() {
  return (
    <Stack gap={3}>
      <Inline justify="between" align="center">
        <Text>Select a range of rows</Text>
        <Shortcut platform="windows" size="sm" variant="soft">
          <Kbd keyName="shift" />
          <Kbd>Click</Kbd>
        </Shortcut>
      </Inline>
      <Inline justify="between" align="center">
        <Text>Add a row to the selection</Text>
        <Shortcut platform="windows" size="sm" variant="soft">
          <Kbd keyName="mod" />
          <Kbd>Click</Kbd>
        </Shortcut>
      </Inline>
    </Stack>
  );
}
```

### What a reader hears

Every mark and every abbreviation hides its legend and carries the word beside it, so ⌘ is announced “Command” rather than “place of interest sign” and Ctrl is not left to a pronunciation dictionary.

Excerpt — not a complete module

```tsx
// “Command Shift K”
<Shortcut keys="mod+shift+k" platform="mac" />;

// “G then I”
<Shortcut keys="g i" />;

// “Any key” — a word the page wrote, so the page owns it.
<Kbd>Any key</Kbd>;
```

### commands.tsx

Example

```tsx
import { Card, CardBody } from '@slotted/react/card';
import { Inline } from '@slotted/react/inline';
import { Shortcut } from '@slotted/react/kbd';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function KbdCommands() {
  return (
    <Card>
      <CardBody>
        <Stack gap={3}>
          <Inline justify="between" align="center">
            <Text>Open command palette</Text>
            <Shortcut keys="mod+k" size="sm" variant="plain" />
          </Inline>
          <Inline justify="between" align="center">
            <Text>Duplicate order</Text>
            <Shortcut keys="mod+d" size="sm" variant="plain" />
          </Inline>
          <Inline justify="between" align="center">
            <Text>Archive order</Text>
            <Shortcut keys="mod+shift+a" size="sm" variant="plain" />
          </Inline>
        </Stack>
      </CardBody>
    </Card>
  );
}
```

### defaults.tsx

Example

```tsx
import { Inline } from '@slotted/react/inline';
import { KbdDefaultsProvider, Shortcut } from '@slotted/react/kbd';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function KbdDefaults() {
  return (
    <KbdDefaultsProvider platform="windows" size="sm" variant="soft">
      <Stack gap={3}>
        <Inline justify="between" align="center">
          <Text>Open search</Text>
          <Shortcut keys="mod+k" />
        </Inline>
        <Inline justify="between" align="center">
          <Text>Create order</Text>
          <Shortcut keys="mod+n" />
        </Inline>
        <Inline justify="between" align="center">
          <Text>Print packing slip</Text>
          <Shortcut keys="mod+p" variant="outline" />
        </Inline>
      </Stack>
    </KbdDefaultsProvider>
  );
}
```

### keys.tsx

Example

```tsx
import { Inline } from '@slotted/react/inline';
import { Kbd } from '@slotted/react/kbd';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function KbdKeys() {
  return (
    <Stack gap={3}>
      <Inline justify="between" align="center">
        <Text>Next field</Text>
        <Kbd keyName="tab" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>Close the panel</Text>
        <Kbd keyName="esc" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>Previous order</Text>
        <Kbd keyName="up" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>Refresh the list</Text>
        <Kbd keyName="f5" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>Open the row menu</Text>
        <Kbd>Right click</Kbd>
      </Inline>
    </Stack>
  );
}
```

### words.tsx

Example

```tsx
import { Inline } from '@slotted/react/inline';
import { Shortcut } from '@slotted/react/kbd';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function KbdWords() {
  return (
    <Stack gap={3}>
      <Inline justify="between" align="center">
        <Text>Remove row</Text>
        <Shortcut
          keys="mod+delete"
          legends={{ mod: 'Control', delete: 'Delete' }}
          names={{ delete: 'Remove' }}
          platform="windows"
        />
      </Inline>
      <Inline justify="between" align="center">
        <Text>Export report</Text>
        <Shortcut keys="mod+shift+e" platform="windows" separator="-" />
      </Inline>
      <Inline justify="between" align="center">
        <Text>Go to inbox</Text>
        <Shortcut keys="g i" messages={{ then: 'followed by' }} />
      </Inline>
    </Stack>
  );
}
```
