Kbd
Keycaps that display a keyboard shortcut next to an action.
- Go to anything
- CommandK
- Save draft
- CommandS
- Publish app
- CommandShiftP
- Run workflow
- OptionR
Usage guidelines
- Show keys, not behavior:
Kbdonly displays a key. The feature registers the shortcut and formats it for the platform, then renders oneKbdper key part. - Group a combination: Wrap the keys of one shortcut in
KbdGroup. Keys sit side by side without a+separator, and each keeps its own<kbd>element. - Keep the action's name clean: Inside a button, menu item or other control, hide the keycaps with
aria-hidden, so the accessible name stays the action, such as "Publish", instead of "Publish ⌘ ⇧ P". When the feature handles the shortcut, also setaria-keyshortcutson the control, such asMeta+Shift+P. Do not declare a shortcut that nothing handles. - Name symbol keys in standalone text: Screen readers announce symbols like
⌘,⇧and⌥inconsistently or not at all. When keycaps are the content itself, such as a shortcut list, hide the symbol witharia-hiddenand put the key name insr-onlytext inside the sameKbd, so the key reads as "Command" once instead of the symbol plus the name. - Do not label
KbdorKbdGroup:<kbd>and the group's<span>have no role that permits naming, soaria-labelandaria-labelledbyon them are not reliably announced. Put the key name in the content instead. - Match the surface:
grayis the default. Usewhiteon a primary button or another dark, saturated surface. Setdisabledwhen the owning control is disabled; it only dims the keycap and adds no ARIA state. - Hint, not entry point: A shortcut in a tooltip is a visual hint for pointer users. The control still needs its own accessible name and a visible way to run the action.
Anatomy
Examples
In a tooltip
The tooltip repeats the trigger's label and adds the keycaps. Assistive technology does not read the tooltip, so a trigger whose shortcut the feature handles sets aria-keyshortcuts. This example only displays the keys and binds no shortcut, so it leaves the attribute off.
In a menu
Each item shows its shortcut at the end of the row. The keycaps are aria-hidden, so the item is announced by its label alone. An item whose shortcut the feature handles also sets aria-keyshortcuts; these items only display keys.
In a button
Use color="white" on a primary button, and dim the keycaps with disabled together with the button.
API reference
Kbd
Displays a single keyboard key or key-like token. Renders a <kbd> element.
| Prop | Type | Default | Details |
|---|---|---|---|
color | 'gray' | 'white' | 'gray' | |
disabled | boolean | false | |
| Attribute | Description |
|---|---|
data-disabled | Present when the key hint belongs to a disabled control. |
KbdGroup
Groups multiple Kbd elements inline without replacing their individual <kbd> semantics. Renders a <span> element.
Accepts the props of the element it renders.