Create

General

Kbd

Copy page View as Markdown Open in ChatGPT Open in Claude

Used to display textual user input from keyboard.

Usage#

app.component.ts
import { WDS_KBD } from '@wds/angular/kbd';

Examples#

Default#

Single keys, modifier symbols and a combination with text between the keys.

⌘ ⇧ ⌥ ⌃ Ctrl + B

Group#

wds-kbd-group keeps keys and text on one line with an even gap.

Use Ctrl + B Ctrl + K to open the command palette

Button#

A key inside a button; an <svg> in wds-kbd gets 12px.

Accept

Input group#

A shortcut hint at the end of a search field.

⌘K

Shortcut#

wds-kbd only displays a key: the app handles the shortcut, usually with one keydown listener on document, so a key described in several places acts once. Check metaKey || ctrlKey and show ⌘ on macOS and Ctrl elsewhere (detect the platform in the browser, not during prerendering). Call preventDefault() when the browser has its own action (⌘S saves the page), skip e.repeat, and avoid shortcuts reserved by the browser or the system (⌘T, ⌘W, ⌘N, ⌘Q). Ignore shortcuts without a modifier (such as /) while the user types in a field.

Save ⌘S

Click the button or press the shortcut.

API References#

wds-kbd#

A key or a keyboard shortcut (<kbd>), e.g. ⌘, Ctrl or Ctrl + K. It only displays the key: it does not listen to the keyboard. wds-kbd-group groups several keys.

Slots

SlotDescription
(default)Key name, symbol or icon (an SVG gets 12px).

CSS parts (::part)

PartDescription
kbdThe native <kbd> element.

CSS custom properties

PropertyDescription
--wds-kbd-bgBackground (default --wds-muted). Change it e.g. on the dark background of a tooltip.
--wds-kbd-fgText color (default --wds-muted-foreground).

wds-kbd-group#

A group of shortcut keys (e.g. Ctrl + B). Plain text can go between the wds-kbd elements.

Slots

SlotDescription
(default)wds-kbd elements and text.

Accessibility#

Screen reader#

wds-kbd renders a native <kbd>; screen readers read its text. Symbols such as ⌘, ⇧ or ⌥ are read differently, or not at all, depending on the screen reader, so do not rely on them alone to explain an action.

A shortcut always complements a visible control (a button, a link) and never replaces it. Describe it on that control with aria-keyshortcuts (e.g. Meta+S); wds-button forwards it to the native button.

wds-kbd-group is only a layout container without a role.

Keyboard support#

wds-kbd has no keyboard interaction and ignores the pointer. The shortcuts it describes are handled by the app.

Footer