Skip to content

Kbd

hc-kbd is a token-driven skin for the native <kbd> element — the semantic tag for “user input from the keyboard”. Use it for single keys (Esc, Enter) and, with hc-kbd-group, for multi-key shortcuts (⌘ + K). It is presentational only — no JavaScript.

EscEnterA

Single-character keys are centered to a square-ish minimum width (--hc-kbd-min-width), so A and Esc line up as a tidy row of caps.

Wrap several keys in hc-kbd-group to compose a shortcut. The group is itself a <kbd> (the whole shortcut is one “keyboard input”); the inner <kbd class="hc-kbd"> are the individual caps. Literal text between them (+, then) is rendered in a muted color so the keys stand out.

+ K

Ctrl + + P

g then i

Set data-size="sm" or data-size="lg" on a key — or on the group to scale every cap inside it at once. Padding and min-width are em-based, so one data-size resizes the whole cap proportionally.

EscEscEsc

+ K

SizeUse for
smInline hints in dense UI (menus, lists).
omittedDefault — body-text shortcuts.
lgProminent shortcut callouts.

hc-kbd slots naturally beside menu items and command rows to advertise their shortcut.

Command palette

+ K

  • A key is announced as its text content, so prefer real text (Ctrl, Esc) where you can.
  • Symbol-only keys (, , ) are read inconsistently by screen readers. Give them an explicit label: <kbd class="hc-kbd" aria-label="Command">⌘</kbd>.
  • A <kbd> is purely descriptive — it is not focusable and does not bind the shortcut. The actual key handling stays on the control the shortcut triggers.
  • Don’t rely on the cap styling alone to convey “this is a key” — the surrounding text (“Press …”) should make the meaning clear.
Token pathPurpose
kbd.bgKeycap background (muted surface).
kbd.fgKey text color.
kbd.borderKeycap border color.
kbd.radiusKeycap corner radius.
kbd.fontMonospace font stack for keys.
kbd.font-sizeDefault key font size.
kbd.font-weightKey font weight.
kbd.padding-x / -yCap padding (em-based, scales with size).
kbd.min-widthMinimum cap width (em-based).
kbd.sm-font-size / lg-font-sizedata-size font sizes.

Colors reference the semantic muted-bg / text / border tokens, so keys follow the active light / dark theme without per-component overrides.

Show the generated CSS variables
--hc-kbd-bg | -fg | -border | -radius
--hc-kbd-font | -font-size | -font-weight
--hc-kbd-padding-x | -padding-y | -min-width
--hc-kbd-sm-font-size | -lg-font-size
  • Command — command palette where shortcut hints commonly appear.
  • Menu — menu items often pair a label with its shortcut.
  • Badge — another small inline token-driven primitive.