Kbd
Draws a key or a whole shortcut for the reader's keyboard, and gives each key a name a screen reader can speak.
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> );}Installation
The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.
pnpm add @slotted/react @slotted/theme @slotted/themesimport { Kbd, KbdDefaultsProvider, Shortcut } from '@slotted/react';A key by name
Kbd in React and slKbd in Angular draw one key. keyName takes 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 esc, cmd, option or arrowup. A key in the vocabulary hides its legend from assistive technology and carries a spoken name beside it: the legend is what the eye reads, the name is what a screen reader says. f1 to f24 are drawn as words with no name. A key written as content, such as Right click, is drawn verbatim: the page owns its wording, so no name is added. keyName wins when both are written. The component draws a key and does not listen for it.
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> );}Variants
variant sets how the key is painted. raised is a key with a bottom edge and the default. outline draws the edge and owns no ground, so it sits on any surface. soft is a tinted chip. plain has no edge and takes the color of the text around it.
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> );}Sizes
xs, sm, md and lg are fixed heights of 16, 20, 24 and 28 pixels. The legend follows the control type scale, so a denser density shrinks it inside the same height. inherit reads the text around the key and stays inside its line: use it in a heading or in fine print, where an absolute height reads as a stamp or a slab.
Press Escape to cancel the count
Press Escape to discard the draft.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> );}One string, every platform
Shortcut in React and slShortcut in Angular draw a combination from one string: keys joins keys pressed together with +. The element is a kbd that holds one kbd per key, as the HTML Standard describes a combination, and the + between two keys is a separate part that assistive technology skips. mod is Command on a Mac and Control elsewhere. platform sets the keyboard the legends are drawn for: mac, windows, linux, other or auto. The modifiers are put in each platform’s own order, so one authored string is right everywhere. A Mac joins its keys with nothing and draws marks (⌘ ⇧), so no + is rendered there. The word for meta differs too: Win on Windows, Super on Linux, Meta otherwise.
auto, the default, reads the browser: navigator.userAgentData.platform, then navigator.platform. The server cannot read it and renders other. React renders other on the server and during hydration, then corrects once the page is hydrated. Angular reads the browser at once and renders other only on the server, where a development-mode warning says so when platform is not stated. A server-rendered page states platform once through the defaults provider and nothing is detected.
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> );}A sequence of steps
Whitespace in keys separates steps, so g i is G, then I. The word between two steps is then, and it is read aloud, because it is the only thing that tells a sequence from a combination. A single letter is drawn in upper case with no name.
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> );}Disabled
disabled dims the key, its rim, its ink and the separators. It writes no aria-disabled, because kbd can carry only the global ARIA attributes: the item the shortcut belongs to owns the semantics. Kbd and Shortcut both take it.
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> );}Beside a command
In a list of commands the label stands first and the shortcut at the end. plain takes the color of the row, so a row that dims takes its shortcut with it and no state is set on the key.
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> );}Words of your own
legends replaces what the eye reads for a key token, and names replaces what a reader hears. separator replaces the + between two keys pressed together, except on a Mac. messages lays words over the keys catalog of the language in force, key by key and for then. A key keeps its mark or its word from the catalog until one of these sets another.
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> );}Defaults for an application
KbdDefaultsProvider in React and provideKbdDefaults in Angular set platform, size, variant, separator, legends and names once for everything below them. A key that states a value of its own keeps it: here the last shortcut states outline.
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> );}Authored keys
Children of Shortcut are keys written by hand and rendered in the order written: this is the way out of the platform ordering. It also holds content outside the vocabulary, such as a click. A Kbd inside takes platform, size, variant and disabled from the shortcut unless it states its own. React also takes render, which substitutes the element; Angular writes the directive on the element the page already owns.
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> );}Accessibility
- 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.
API
Kbd
Props
keyNamestring- 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.
keysstring- On ShortcutThe whole combination: + joins keys pressed together, whitespace joins the steps of a sequence.
platform'auto' | 'mac' | 'windows' | 'linux' | 'other'Defaultauto- On Kbd, ShortcutWhich keyboard the legends are drawn for. auto reads the browser; state it where the page is server-rendered.
size'xs' | 'sm' | 'md' | 'lg' | 'inherit'Defaultmd- On Kbd, Shortcutxs 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'Defaultraised- On Kbd, Shortcutraised 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.
disabledbooleanDefaultfalse- On Kbd, ShortcutDims the key without writing aria-disabled, which kbd may not carry. The item the shortcut belongs to owns the semantics.
separatorstringDefault+- On ShortcutBetween two simultaneous keys. A Mac joins with nothing whatever this says.
messagesPartialMessages<KeysMessages>- On Kbd, ShortcutWords 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.
legendsRecord<string, string>- On ShortcutReplaces what the eye sees, per key token: { mod: "Control" }. Falls back to the provider.
namesRecord<string, string>- On ShortcutReplaces what a reader hears, per key token: { delete: "Remove" }. Falls back to the provider.
Composition
childrenReactNode- The legend written verbatim — the application’s own word, neither resolved nor given a hidden name.
childrenReactNode- On ShortcutKeys authored one by one. They are rendered in the order written, which is the way out of the platform reordering.
render(props: KbdRootProps) => ReactNode- On Kbd, ShortcutSubstitutes the rendered element. Every data attribute and every part are handed to it.
refRef<HTMLElement>- On Kbd, ShortcutReaches 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 }- On a subtreeSets all six once for everything below it; an explicit prop on a key still wins.
Parts
| Part | Element | Required | Purpose |
|---|---|---|---|
root | kbd | Yes | One key. Carries data-ui="kbd", the axes as data attributes, data-key when the token is in the vocabulary, and every native attribute the consumer passes. |
legend | span | Yes | What the eye sees. Hidden from assistive technology whenever the key is in the vocabulary, and marked data-legend="symbol" when what it draws is a mark rather than a word. |
name | span | No | What a reader hears in place of the legend — “Command”, “Control”, “Up arrow”. Clipped from view by a rule of Kbd’s own. Rendered only for a key in the vocabulary. |
shortcut | kbd | No | A whole combination, holding the key roots. The one part that contains the root instead of sitting inside it, so it carries data-ui itself, plus data-platform for the resolution it made. |
separator | span | No | Between two keys. data-separator="plus" joins keys pressed together and is hidden from assistive technology; data-separator="then" joins two steps of a sequence and is read aloud. |
Theming
Each token is a CSS custom property: set it in a theme, or on any element to retune every kbd inside it.
Kbd tokens
| Token | Default |
|---|---|
--slotted-kbd-base-width | var(--slotted-border-width-thick, 2px) |
--slotted-kbd-border-color | var(--slotted-control-border-color, ButtonBorder) |
--slotted-kbd-border-width | var(--slotted-border-width-thin, 1px) |
--slotted-kbd-color | var(--slotted-text, CanvasText) |
--slotted-kbd-font-family | var(--slotted-control-font-family, sans-serif) |
--slotted-kbd-font-weight | var(--slotted-font-weight-medium, 500) |
--slotted-kbd-radius | var(--slotted-radius-md, 6px) |
--slotted-kbd-surface | var(--slotted-surface-raised, Canvas) |
--slotted-kbd-symbol-font-family | var(--slotted-font-family-sans, sans-serif) |
Theme tokens it reads
| Token | Default |
|---|---|
--slotted-border-strong | Set per scheme by the theme |
--slotted-border-width-thick | 2px |
--slotted-border-width-thin | 1px |
--slotted-control-border-color | Set per scheme by the theme |
--slotted-control-font-family | var(--slotted-font-family-sans) |
--slotted-control-font-size-lg | comfortable 14px · compact 13px · dense 12px |
--slotted-control-font-size-md | comfortable 13px · compact 12px · dense 12px |
--slotted-control-font-size-sm | comfortable 12px · compact 12px · dense 12px |
--slotted-control-inner-size | var(--_size) |
--slotted-control-transition-duration | var(--slotted-duration-short) |
--slotted-control-transition-easing | var(--slotted-easing-standard) |
--slotted-disabled-background | Set per scheme by the theme |
--slotted-disabled-border | Set per scheme by the theme |
--slotted-disabled-foreground | Set per scheme by the theme |
--slotted-font-family-sans | 'Geist Variable', ui-sans-serif, system-ui, sans-serif |
--slotted-font-weight-medium | 500 |
--slotted-radius-lg | 8px |
--slotted-radius-md | 6px |
--slotted-radius-sm | 4px |
--slotted-space-1 | 0.125rem |
--slotted-space-2 | 0.25rem |
--slotted-space-3 | 0.375rem |
--slotted-space-4 | 0.5rem |
--slotted-space-6 | 1rem |
--slotted-space-7 | 1.25rem |
--slotted-space-8 | 1.5rem |
--slotted-surface-raised | Set per scheme by the theme |
--slotted-text | Set per scheme by the theme |
--slotted-text-box-edge | cap alphabetic |
--slotted-text-muted | Set per scheme by the theme |
--slotted-tone-secondary-border | Set per scheme by the theme |
--slotted-tone-secondary-surface | Set per scheme by the theme |
--slotted-tone-secondary-text | Set per scheme by the theme |