Kbd

Keyboard shortcut web component: keys drawn as key caps (Mod+K is ⌘K on Apple platforms, Ctrl+K elsewhere), read out by name.

  • 3.0 KB gzipped
  • @lit-material/kbd 1.8.0
  • Renders on the server

Example

Install

npm install @lit-material/kbd @lit-material/tokens
import "@lit-material/kbd";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-kbd>

A keyboard shortcut, drawn as keys: Mod+K is ⌘K on Apple platforms and Ctrl+K elsewhere. Screen readers hear the keys' names ("Command K"), not the symbols.

Properties

PropertyAttributeTypeDefaultDescription
keyskeysstring""The shortcut, e.g. Mod+K, Mod+Shift+P, Alt+Shift+ArrowLeft, G I (a sequence).
platformplatformKbdPlatform"auto"auto (default) detects it in the browser; apple or other pins it.
sizesizeKbdSize"small"small (default, for menus and hints) or medium.
spokenTextproperty onlystringnoneThe text read out, e.g. "Command Shift P" or "G, then I".

CSS parts

PartDescription
keysThe drawn keys (hidden from assistive technology).
keyEach key cap.
labelThe spoken text (visually hidden).

CSS custom properties

PropertyDescription
--lit-material-kbd-fontThe keys' font (default: the system monospace).
--lit-material-kbd-backgroundThe key caps' background.
--lit-material-kbd-colorThe key caps' text colour.
--lit-material-kbd-borderThe key caps' border colour.

Source on GitHub npm