Skip to contentKino
Skip to Content

Kbd

A key or a shortcut, drawn as keys that fit the text around them. Mod is ⌘ on a Mac and Ctrl elsewhere, and each key sinks while it is held.

npx shadcn add https://kinoui.com/r/kbd.json
Share on

Examples

Keyboard shortcuts

Create issue
C
Search
Slash
Go to inbox
GthenI
Bold
CtrlB
Redo
CtrlShiftZ
Next issue
JorDown arrow

Default

One key, or a KbdGroup of keys pressed together. Write Mod for ⌘ on a Mac and Ctrl elsewhere; modifiers are drawn and ordered the platform’s way, so this Redo reads ⇧⌘Z on a Mac and Ctrl Shift Z elsewhere. Hold a key to see it sink.

Press Question mark to see every shortcut.

Press CtrlK to open the command menu from anywhere.

Esc closes it

In text

A key is sized in em and takes the colour of the text around it, so it fits small print, a paragraph and a heading alike.

KN-482 · Billing

Invoices sent before the 3rd show last month's exchange rate. Recalculate the total when the rate changes, and say so in the invoice's history.

In a field, a button, a tooltip and a menu

Keys answer the shortcuts they show: press / to search or Mod S to save. Put aria-keyshortcuts on the control the shortcut runs.

inv
  • Invoices: KN-482 Recalculate totals on rate change
  • Invite members to Billing
Up arrowDown arrowMoveEnterOpenEscClose

Icons

An icon as the label needs name, the key as KeyboardEvent.key names it, so the key knows when it is held and what a screen reader should say.

Installation

npx shadcn@latest add https://kinoui.com/r/kbd.json
Files
lib/keys.tsxlib/reduce-motion.tscomponents/kino/kbd.tsx

New to Kino? Installation covers what your project needs first and the @kino namespace.

API reference

Kbd

PropTypeDefaultDescription
childrenReactNodeNoneThe label: K, Esc, Page Down, Mod, or an icon. Leave it out to draw the key named by name.
namestringNoneThe key, as KeyboardEvent.key names it (ArrowUp, Enter, Backspace), or Mod. Read from the label when it is text; needed when the label is an icon.

Data attributes

AttributeOnDescription
data-heldKbdPresent while the person holds the key down, outside a text field. Keys typed into a field don’t count.

CSS variables

VariableSet it onDefaultDescription
--kbd-sinkKbd, or <body>1pxHow far a held key sinks. Under reduced motion it doesn’t move.

Accessibility

  • A key whose label is a symbol (⌘, ⇧, ↵, /) hides the symbol from screen readers and reads words in its place, such as “Command K”, since screen readers speak symbols unevenly and ignore a name on a <kbd>.
  • A hint doesn’t run its shortcut. Put aria-keyshortcuts on the control the shortcut runs, so a screen reader announces it there.
  • A held key sinks and its edge flattens; in forced colours it takes the system’s highlight.
  • Write words such as “then” and “or” outside the keys, so they aren’t read as keys.