Skip to main content

Kbd

A keyboard key or shortcut, shown as text.

Left out of Accessible first Kbd tells people the shortcut for an action. Here people do this once or twice a year, and nobody remembers the interface from last time. Use instead: Label

See it live​

Start Storybook to see it live: npm run storybook

When to use it​

  • Use it when: Telling people the shortcut for an action.
  • Not when: Decoration, or the only way to discover an action.

Instead:

  • Command: Where shortcuts are often listed.

Words​

  • Use common words. Explain any term you must use.
  • One idea per sentence. Put the action first.
  • Never blame the person.
  • Use: Continue, Change, Start, You. Avoid: Invalid, Utilise, Submit, Error code.

The labels components use, from the voice tokens:

  • content.action.commit: Continue
  • content.action.cancel: Go back
  • content.action.destroy: Delete
  • content.action.retry: Try again
  • content.action.empty-action: Start a new application

See Voice and tone for the whole voice.

Use it in code​

npx open-ds add kbd

The component reads only component keys and semantic tokens, so it follows the brand and mode on <html>.

Tokens it reads​

Kbd reads 10 tokens of its own, each an alias of a semantic token. Each row is one part: its own token, the semantic it aliases, and the value it ends at. Change a semantic and every component that reads it follows; override one of Kbd's tokens to change Kbd alone.

Changes with theme

Accessible first decides what changes when you switch theme. Here a switch changes colors only, so the marked rows differ between light and dark; everything else holds steady.

PartIts token and the semantic it aliasesValue
Kbd
Gapcomponent.kbd.gapspace.gap.tightvar(--kbd-gap)space.12:0.75rem
Cornercomponent.kbd.radiusradius.badgevar(--kbd-radius)radius.4:0.25rem
Fill
Changes with theme
component.kbd.backgroundcolor.surface.sunkenvar(--kbd-background)Lightgray.light.100:#EDEDEDDarkgray.dark.100:#222222
Padding, left and rightcomponent.kbd.padding-xcomponent-spacing-map.x1var(--kbd-padding-x)space.4:0.25rem
Text sizecomponent.kbd.font-sizetype.caption.font-sizevar(--kbd-font-size)font.size.16:1rem
Weightcomponent.kbd.font-weighttype.label.font-weightvar(--kbd-font-weight)font.weight.700:700
Text
Changes with theme
component.kbd.labelcolor.text.mutedvar(--kbd-label)Lightgray.light.500:#595959Darkgray.dark.500:#949494
Background 2
Changes with theme
component.kbd.background-2color.surface.canvasvar(--kbd-background-2)Lightgray.light.50:#F7F7F7Darkgray.dark.0:#0A0A0A
Label 2
Changes with theme
component.kbd.label-2color.surface.canvasvar(--kbd-label-2)Lightgray.light.50:#F7F7F7Darkgray.dark.0:#0A0A0A
Group
Gapcomponent.kbd.group.gapspace.gap.tightvar(--kbd-group-gap)space.12:0.75rem