Kbd
Kbd displays a keyboard key combination, such as a shortcut in documentation or a hint within the UI.
Overview
Kbd shows the keys that make up a keyboard shortcut as individual, key-shaped glyphs. It lets users recognize a shortcut at a glance, whether it’s described in help text or documentation, or surfaced as a hint next to a menu item or button.
Kbd is typically paired with menu items, buttons, tooltips, and help content that describe an action alongside the shortcut that triggers it.
Usage
forge-kbd renders the modifier keys you turn on with ctrl, alt, shift, meta, and mod, followed by the keys listed in keys. It only displays a shortcut; use keyboard shortcut to actually listen for one. Use mod for the primary modifier of the current platform, which shows ⌘ on Apple platforms and Ctrl elsewhere, and dense, muted, and theme to adapt the appearance to its surroundings.
Rules
Basic usage
Set the modifier properties you need and list the remaining keys in keys.
A kbd showing the Shift and K keys.
<forge-kbd shift keys="K">
</forge-kbd>Key strings
keys takes an array of strings. As an attribute it takes a space-separated list. Some keys are shown as glyphs or friendlier names: ArrowUp, ArrowDown, ArrowLeft, and ArrowRight show arrows, Escape shows Esc, and Enter shows Return on Apple platforms. Every other key is shown as provided, converted to title case.
A kbd showing arrow keys and a named key.
<div class="flex flex-wrap items-center gap-medium">
<forge-kbd keys="ArrowUp">
</forge-kbd>
<forge-kbd keys="ArrowDown">
</forge-kbd>
<forge-kbd keys="ArrowLeft">
</forge-kbd>
<forge-kbd keys="ArrowRight">
</forge-kbd>
<forge-kbd keys="Enter">
</forge-kbd>
<forge-kbd keys="Escape">
</forge-kbd>
<forge-kbd keys="PageDown">
</forge-kbd>
</div>Modifier keys
Modifiers are shown with platform-appropriate glyphs, in the order Control, Alt, Shift, Meta, then Mod, followed by keys.
<forge-kbd mod keys="S"></forge-kbd>
Kbd with each modifier key turned on.
<div class="flex flex-wrap items-center gap-medium">
<forge-kbd ctrl keys="S">
</forge-kbd>
<forge-kbd alt keys="S">
</forge-kbd>
<forge-kbd shift keys="S">
</forge-kbd>
<forge-kbd meta keys="S">
</forge-kbd>
<forge-kbd mod keys="S">
</forge-kbd>
<forge-kbd ctrl alt shift keys="Delete">
</forge-kbd>
</div>Dense
Set dense to render smaller keys that fit within compact UI.
A dense kbd.
<div class="flex flex-wrap items-center gap-medium">
<forge-kbd dense mod keys="K">
</forge-kbd>
<forge-kbd dense ctrl shift keys="P">
</forge-kbd>
</div>Muted
Set muted to render the keys without outlines when the shortcut is secondary information.
A muted kbd.
<div class="flex flex-wrap items-center gap-medium">
<forge-kbd muted mod keys="K">
</forge-kbd>
<forge-kbd muted ctrl shift keys="P">
</forge-kbd>
</div>Theme
Set theme to one of primary, secondary, tertiary, info, success, warning, or error to color the keys.
Kbd in each theme.
<div class="flex flex-wrap items-center gap-medium">
<forge-kbd theme="primary" shift keys="K">
</forge-kbd>
<forge-kbd theme="secondary" shift keys="K">
</forge-kbd>
<forge-kbd theme="tertiary" shift keys="K">
</forge-kbd>
<forge-kbd theme="info" shift keys="K">
</forge-kbd>
<forge-kbd theme="success" shift keys="K">
</forge-kbd>
<forge-kbd theme="warning" shift keys="K">
</forge-kbd>
<forge-kbd theme="error" shift keys="K">
</forge-kbd>
</div>Displays a keyboard key combination made up of modifier and alphanumeric keys.
import "@tylertech/forge/kbd";| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
keys | keys | string[] | [] | A space-separated list of alphanumeric keys to display. |
alt | alt | boolean | false | Whether to display the Alt key (Option/⌥ on Apple keyboards or Alt on Windows keyboards). |
ctrl | ctrl | boolean | false | Whether to display the Control key (Control/⌃ on Apple keyboards or Ctrl on Windows keyboards). |
meta | meta | boolean | false | Whether to display the Meta key (Command/⌘ on Apple keyboards or ⊞ on Windows keyboards). |
mod | mod | boolean | false | Whether to display the platform-specific mod key (Command/⌘ on Apple keyboards or Ctrl on Windows keyboards). |
shift | shift | boolean | false | Whether to display the Shift key. |
dense | dense | boolean | false | Whether to display the keys in compact style. |
theme | theme | string | '' | The theme to apply to the keyboard keys. |
muted | muted | boolean | false | Renders the keys without outlines. |
| Name | Description |
|---|---|
::part(root) | The root container element. |
::part(key) | Each individual rendered `<kbd>` key element. |
| Name | Description |
|---|---|
--forge-kbd-background | The background color of the keyboard keys. |
--forge-kbd-color | The text color of the keyboard keys. |
--forge-kbd-shape | The border radius of the keyboard keys. |
--forge-kbd-block-size | The block size of the keyboard keys. The inline size is automatically calculated based on the block size. |
--forge-kbd-padding-inline | The inline padding of the keyboard keys. |
--forge-kbd-border-width | The border width of the keyboard keys. |
--forge-kbd-border-style | The border style of the keyboard keys. |
--forge-kbd-border-color | The border color of the keyboard keys. |
--forge-kbd-gap | The spacing between rendered keys. |
Screen reader behavior
forge-kbd renders native <kbd> elements, which assistive technology recognizes as keyboard input. Each key is rendered in its own <kbd> inside a wrapping <kbd>, so a screen reader can read the combination in order. When only one key is shown, the wrapper gets role="presentation" so the key isn’t announced twice.
Labeling
forge-kbd isn’t focusable and has no accessible name of its own. Always describe the action in nearby text, and don’t rely on the glyphs alone.
If the shortcut is actually bound to an element, expose it with aria-keyshortcuts on that element, since forge-kbd is only a visual representation. Use keyboard shortcut to wire up the behavior itself.
Platform glyphs
Modifier keys and some named keys are shown with different glyphs on Apple platforms (for example ⌘ instead of Ctrl). Screen readers may read symbols such as ⌘ and ⇧ differently than the key names, so describe the shortcut in text wherever it matters.