Skip to content

Kbd

Keycaps that display a keyboard shortcut next to an action.

Go to anything
CommandK
Save draft
CommandS
Publish app
CommandShiftP
Run workflow
OptionR
hero.tsx

Usage guidelines

  • Show keys, not behavior: Kbd only displays a key. The feature registers the shortcut and formats it for the platform, then renders one Kbd per 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 set aria-keyshortcuts on the control, such as Meta+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 with aria-hidden and put the key name in sr-only text inside the same Kbd, so the key reads as "Command" once instead of the symbol plus the name.
  • Do not label Kbd or KbdGroup: <kbd> and the group's <span> have no role that permits naming, so aria-label and aria-labelledby on them are not reliably announced. Put the key name in the content instead.
  • Match the surface: gray is the default. Use white on a primary button or another dark, saturated surface. Set disabled when 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

tsx
tsx

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.

tooltip.tsx

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.

menu.tsx

In a button

Use color="white" on a primary button, and dim the keycaps with disabled together with the button.

button.tsx

API reference

Kbd

Displays a single keyboard key or key-like token. Renders a <kbd> element.

Props
PropTypeDefaultDetails
color'gray' | 'white''gray'
disabledbooleanfalse
Data attributes
AttributeDescription
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.