KbdShortcut

KbdShortcut renders a keyboard shortcut such as Ctrl + K as an outer <kbd> holding one inner <kbd> per key with a decorative separator between them. Use kbd for a single key reference.

Status: beta — implemented and unit-tested in the Svelte canonical; ports to the other frameworks pending (2026-10-05)

Implementation Notes

  • Root <kbd class="kbd-shortcut"> containing, per key, <kbd class="kbd-shortcut-key">
  • Between keys: <span class="kbd-shortcut-separator" aria-hidden="true"> containing separator (default +)
  • Optional label becomes aria-label on the root as the spoken form; absent, screen readers read the keys
  • Spreads restProps onto the root

Props

  • className: string (default: "") -- CSS class name appended to the base class
  • keys: string[] (required) -- the key names, in order
  • separator: string (default: "+") -- decorative separator between keys
  • label: string (optional) -- spoken form, applied as aria-label
  • ...restProps: unknown -- additional attributes spread onto the root

Usage

<KbdShortcut keys={["Ctrl", "K"]} label="Control K" />
<KbdShortcut keys={["G", "H"]} separator=" then " />

Keyboard Interactions

  • None. KbdShortcut is a passive display element

ARIA

  • Separators are aria-hidden="true" so they are not read
  • aria-label={label} -- optional spoken form on the root

When to Use

  • Use to show a multi-key shortcut in menus, help panels and command palettes.
  • Use where the keys, order and separator should be consistent.
  • Use in onboarding that teaches shortcuts.

When Not to Use

  • Do not use for a single key -- use kbd.
  • Do not use for code or commands -- use code or code-block.
  • Do not use to make a shortcut work -- it only displays one.

Headless

This headless component renders nested <kbd> elements. Keycap appearance, spacing and separator styling are consumer CSS; no key icons are bundled.

Styles

The consumer provides all CSS styling via .kbd-shortcut, .kbd-shortcut-key and .kbd-shortcut-separator.

Testing

  • Verify the root is a <kbd> with class kbd-shortcut
  • Verify one inner kbd-shortcut-key per key, in order
  • Verify separators only between keys, default +, configurable, aria-hidden
  • Verify label becomes aria-label
  • Verify pass-through attributes

Advice

  • Designers: Style platform-appropriate key names; show Cmd on macOS and Ctrl elsewhere.
  • Developers: Detect the platform in your app and pass the right keys; this component does no detection or localisation.

Related components

  • kbd — a single key
  • code — inline code
  • menu — menus that often show shortcuts

References


Lily™ and Lily Design System™ are trademarks.

Example

CtrlK
Show demo markup
<kbd class="kbd-shortcut"><kbd class="kbd-shortcut-key">Ctrl</kbd><span class="kbd-shortcut-separator" aria-hidden="true">+</span><kbd class="kbd-shortcut-key">K</kbd></kbd>

Three keys

CmdShiftP
Show markup
<kbd class="kbd-shortcut"><kbd class="kbd-shortcut-key">Cmd</kbd><span class="kbd-shortcut-separator" aria-hidden="true">+</span><kbd class="kbd-shortcut-key">Shift</kbd><span class="kbd-shortcut-separator" aria-hidden="true">+</span><kbd class="kbd-shortcut-key">P</kbd></kbd>
Usage example
<KbdShortcut keys={["Ctrl", "K"]} label="Control K" />
<KbdShortcut keys={["G", "H"]} separator=" then " />
Show Svelte source
// In your Svelte component:
import KbdShortcut from "lily-design-system-svelte-headless/components/KbdShortcut/KbdShortcut.svelte";

<KbdShortcut>
  <!-- content -->
</KbdShortcut>

Canonical contract

Generated from this component's canonical metadata — the machine-checked source the implementations are held to.

Metadata

  • Component: kbd-shortcut
  • PascalCase: KbdShortcut
  • Description: a multi-key keyboard shortcut shown as a row of key caps
  • Status: beta — implemented and unit-tested in the Svelte canonical; ports to the other frameworks pending (2026-10-05)
  • HTML tag: <kbd>
  • CSS class: .kbd-shortcut
  • Interactive: no

ARIA

  • Separators are aria-hidden="true" so they are not read
  • aria-label={label} -- optional spoken form on the root

Keyboard

  • None. KbdShortcut is a passive display element

Props

  • className: string (default: "") -- CSS class name appended to the base class
  • keys: string[] (required) -- the key names, in order
  • separator: string (default: "+") -- decorative separator between keys
  • label: string (optional) -- spoken form, applied as aria-label
  • ...restProps: unknown -- additional attributes spread onto the root