StartFoundationsComponentsContent

Kbd

Kbd shows a keyboard shortcut as a row of keys. It names symbol keys for screen readers and shows ⌘ on a Mac and Ctrl elsewhere.

Stable Figma
OverviewUsageAPIAccessibility
<tk-kbd keys="Mod+K"></tk-kbd>
<tk-kbd keys="Mod+Shift+P"></tk-kbd>
<tk-kbd keys="Esc"></tk-kbd>

Anatomy

Part What it is
tk-kbd the element; inline, not focusable, no role
key part each key, a native <kbd>
separator part the + between keys, in bare only

A symbol key such as ⌘ or ↑ shows the symbol and gives screen readers a word, such as "Command" or "Up arrow". A letter or word key, such as K or F5, is plain text.

Variants

<tk-kbd keys="Mod+K"></tk-kbd>
<tk-kbd keys="Mod+K" treatment="bare"></tk-kbd>
  • chip (default): each key on a soft filled plate. Use it where the shortcut is the point: palette footers, tips, cheat sheets.
  • bare: quiet secondary text with + between keys. Use it where the shortcut trails a label, such as in the trailing slot of a Menu item.

Keys

Write the keys in the keys attribute, joined by +. Case doesn't matter for named keys.

Write Shows on a Mac Shows elsewhere
Mod ⌘ Ctrl
Ctrl, Control ⌃ Ctrl
Alt, Option, Opt ⌥ Alt
Shift ⇧ Shift
Cmd, Command ⌘ ⌘
Enter, Return ⏎ ⏎
Backspace / Delete, Del ⌫ / ⌦ ⌫ / ⌦
Up, Down, Left, Right ↑ ↓ ← → ↑ ↓ ← →
Esc, Tab, Space the word the word

Anything else, such as K, 5, or F5, shows as written. Symbols typed directly, such as ⌘ or ↵, are named for screen readers too.

A +, ,, or space key can't go in the attribute. Set the keys property to an array instead, or write Space:

document.querySelector('tk-kbd').keys = ['Ctrl', '+'];

Platform

<tk-kbd keys="Mod+S" platform="mac"></tk-kbd>
<tk-kbd keys="Mod+S" platform="windows"></tk-kbd>

platform is auto by default: Kbd checks the reader's operating system. Set mac, windows, or linux to fix it. windows and linux look the same.

  • Use Mod for the main modifier, the one that's ⌘ on a Mac and Ctrl elsewhere. Ctrl always means the Control key, so on a Mac it shows ⌃, not ⌘.
  • auto sees the operating system, not the keyboard. A PC keyboard on a Mac, remapped keys, or a remote desktop can make it wrong. If your shortcut code decides the modifier another way, set platform to match it.