Skip to content
Slotted

Kbd

Draws a key or a whole shortcut for the reader's keyboard, and gives each key a name a screen reader can speak.

Search ordersControlK

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.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes
tsx
import { 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.

Next fieldTab
Close the panelEscape
Previous orderUp arrow
Refresh the listF5
Open the row menuRight click

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.

raisedControlB
outlineControlB
softControlB
plainControlB

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.

EscapeEscapeEscapeEscape

Press Escape to cancel the count

Press Escape to discard the draft.

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.

macShiftCommandS
windowsWindowsShiftS
linuxSuperShiftS
otherMetaShiftS
autoMetaShiftS

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.

Go to the inboxGthenI
Go to ordersGthenO
ShortcutsControlKthenControlS

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.

Approve payment runControlEnter
Reverse postingControlShiftR
Dispatch to carrierEnter

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.

Open command paletteControlK
Duplicate orderControlD
Archive orderControlShiftA

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.

Remove rowControlRemove
Export reportControlShiftE
Go to inboxGfollowed byI

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.

Open searchControlK
Create orderControlN
Print packing slipControlP

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.

Select a range of rowsShiftClick
Add a row to the selectionControlClick

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'Default auto
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'Default md
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'Default raised
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.
disabledbooleanDefault false
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

PartElementRequiredPurpose
rootkbdYesOne 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.
legendspanYesWhat 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.
namespanNoWhat 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.
shortcutkbdNoA 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.
separatorspanNoBetween 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

TokenDefault
--slotted-kbd-base-widthvar(--slotted-border-width-thick, 2px)
--slotted-kbd-border-colorvar(--slotted-control-border-color, ButtonBorder)
--slotted-kbd-border-widthvar(--slotted-border-width-thin, 1px)
--slotted-kbd-colorvar(--slotted-text, CanvasText)
--slotted-kbd-font-familyvar(--slotted-control-font-family, sans-serif)
--slotted-kbd-font-weightvar(--slotted-font-weight-medium, 500)
--slotted-kbd-radiusvar(--slotted-radius-md, 6px)
--slotted-kbd-surfacevar(--slotted-surface-raised, Canvas)
--slotted-kbd-symbol-font-familyvar(--slotted-font-family-sans, sans-serif)

Theme tokens it reads

TokenDefault
--slotted-border-strongSet per scheme by the theme
--slotted-border-width-thick2px
--slotted-border-width-thin1px
--slotted-control-border-colorSet per scheme by the theme
--slotted-control-font-familyvar(--slotted-font-family-sans)
--slotted-control-font-size-lgcomfortable 14px · compact 13px · dense 12px
--slotted-control-font-size-mdcomfortable 13px · compact 12px · dense 12px
--slotted-control-font-size-smcomfortable 12px · compact 12px · dense 12px
--slotted-control-inner-sizevar(--_size)
--slotted-control-transition-durationvar(--slotted-duration-short)
--slotted-control-transition-easingvar(--slotted-easing-standard)
--slotted-disabled-backgroundSet per scheme by the theme
--slotted-disabled-borderSet per scheme by the theme
--slotted-disabled-foregroundSet per scheme by the theme
--slotted-font-family-sans'Geist Variable', ui-sans-serif, system-ui, sans-serif
--slotted-font-weight-medium500
--slotted-radius-lg8px
--slotted-radius-md6px
--slotted-radius-sm4px
--slotted-space-10.125rem
--slotted-space-20.25rem
--slotted-space-30.375rem
--slotted-space-40.5rem
--slotted-space-61rem
--slotted-space-71.25rem
--slotted-space-81.5rem
--slotted-surface-raisedSet per scheme by the theme
--slotted-textSet per scheme by the theme
--slotted-text-box-edgecap alphabetic
--slotted-text-mutedSet per scheme by the theme
--slotted-tone-secondary-borderSet per scheme by the theme
--slotted-tone-secondary-surfaceSet per scheme by the theme
--slotted-tone-secondary-textSet per scheme by the theme