Skip to content

Kbd

Keycaps and keycap groups.

Kbd is one keycap and KbdGroup holds the keys of one shortcut. On a touch-only tablet (a coarse pointer, 768px or wider, no mouse or trackpad) the item's stylesheet hides every kbd element on the page, this component or not. Never let a sentence depend on a keycap.

Keycaps

⌘⇧KEscEnterSpace

Key combinations

Search
⌘K
New task
C
Assign to me
⇧A
Close the panel
Esc

In a button

In a tooltip

Installation

npx shadcn@latest add @khaeli/kbd

Install @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.

Installs with

Registry items

Accessible name

  • A keycap is read as its text, and it joins the name of the control that holds it: a button with the keys ⌘ and K is named Search tasks ⌘ K. To keep the name to the action, hide the keys with aria-hidden and declare the shortcut on the control with aria-keyshortcuts.
  • A tooltip is not tied to its trigger for assistive technology, so a shortcut shown only in a tooltip needs aria-keyshortcuts on the trigger too.
  • Write a key as a word (Esc, Enter) unless its symbol is the usual form.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/kbd.json