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
Kbd
A keyboard shortcut drawn as key caps. Mod is ⌘ on Apple platforms and Ctrl elsewhere; screen readers hear the keys' names.
This platform
Pinned
Apple:
Medium
Send the request with
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
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
keys | keys | string | "" | The shortcut, e.g. Mod+K, Mod+Shift+P, Alt+Shift+ArrowLeft, G I (a sequence). |
platform | platform | KbdPlatform | "auto" | auto (default) detects it in the browser; apple or other pins it. |
size | size | KbdSize | "small" | small (default, for menus and hints) or medium. |
spokenText | property only | string | none | The text read out, e.g. "Command Shift P" or "G, then I". |
CSS parts
| Part | Description |
|---|---|
keys | The drawn keys (hidden from assistive technology). |
key | Each key cap. |
label | The spoken text (visually hidden). |
CSS custom properties
| Property | Description |
|---|---|
--lit-material-kbd-font | The keys' font (default: the system monospace). |
--lit-material-kbd-background | The key caps' background. |
--lit-material-kbd-color | The key caps' text colour. |
--lit-material-kbd-border | The key caps' border colour. |