Kbd
Introduction
Section titled “Introduction”Shows a keyboard shortcut such as “Ctrl+S” as keycaps. Kbd takes the hotkey syntax of matchesHotkey from @absoluteui/utilities (“Mod+Shift+K”), so a shortcut is written once and displayed for the user’s platform: on Apple platforms Mod is Command and modifiers show as symbols, each followed by its name for assistive technology; elsewhere Mod is Ctrl and keys are joined by “+”. It only displays; it never listens for keys.
- Platform awareMod becomes Command on Apple devices and Ctrl elsewhere.
- Hotkey stringsPass a combination like Mod+Shift+K and get separate keycaps.
- Readable namesSymbol keys carry a visually hidden name for screen readers.
- Inline or standaloneSits inside text or on its own in two sizes.
Use it for
- Documenting a shortcut next to the command it triggers: menu items, tooltips, help pages.
- Showing a key the user should press, such as Esc or Enter.
Use something else for
- Code or command-line text: use a code element.
- Interactive key remapping: Kbd only displays.
Anatomy
<span class="aui-kbd aui-kbd--{size}"> <kbd class="aui-kbd__combo"> <kbd class="aui-kbd__key">Ctrl</kbd> <span class="aui-kbd__separator">+</span> (not on Apple platforms) <kbd class="aui-kbd__key"> <span aria-hidden="true">symbol</span><span>Name (visually hidden)</span> (symbol keys) </kbd> </kbd></span>Live example
Section titled “Live example”Use the bar above each frame to switch theme, density, direction, and locale.
Kbd in the Team profile showcase
Section titled “Kbd in the Team profile showcase”The part of the Team profile showcase that uses Kbd. Change its options, use it with the keyboard, and watch the event log; the link in the frame opens the full showcase. The bar above the frame switches theme, density, direction, and locale.
Showcase source
// Layout and content showcase: a team profile page built with the layout primitives, cards,// typography, badges, keyboard keys, avatars, an avatar group, and a tag group.import { Avatar } from '@absoluteui/components/avatar';import { AvatarGroup } from '@absoluteui/components/avatar-group';import { Badge } from '@absoluteui/components/badge';import { Card } from '@absoluteui/components/card';import { Kbd } from '@absoluteui/components/kbd';import { Container, Divider, Flex, Grid, Stack } from '@absoluteui/components/layout';import { TagGroup, type TagGroupChangeDetail } from '@absoluteui/components/tag-group';import { Heading, Link, Text } from '@absoluteui/components/typography';import { annotate, choice, createShowcase, hostIn, toggle } from './kit.js';
const sc = createShowcase({ title: 'Team profile', description: 'Layout primitives and content components composing a real page. Resize the frame: the grid reflows.',});
const page = hostIn(sc.stage);Container.apply(page, { size: 'lg' });const stack = Stack.apply(page, { gap: 6 });
// Each block of the page declares its components (focus mode shows a component's own blocks).// Header.const header = annotate(hostIn(page), ['layout', 'avatar', 'typography', 'badge']);const headerFlex = Flex.apply(header, { gap: 4, align: 'center', wrap: true });const avatar = Avatar.create(hostIn(header), { name: 'Platform Engineering', size: 'xl', shape: 'square', icon: 'code' });const titles = hostIn(header);Stack.apply(titles, { gap: 1 });titles.append(Heading.create(2, 'Platform Engineering', { size: 3 }), Text.create('Builds and runs the internal developer platform.', { tone: 'muted' }));const badges = hostIn(titles);Flex.apply(badges, { gap: 2, wrap: true });const badgeList = [ Badge.create(hostIn(badges), { label: 'Hiring', tone: 'success', dot: true }), Badge.create(hostIn(badges), { label: '14 members', tone: 'neutral' }), Badge.create(hostIn(badges), { label: 'On call', tone: 'warning', variant: 'outline', icon: 'clock' }),];
// Members grid of cards.const members = annotate(hostIn(page), ['layout', 'card', 'avatar', 'typography']);Stack.apply(members, { gap: 4 });members.append(Divider.create({ label: 'Members' }));const grid = hostIn(members);const gridLayout = Grid.apply(grid, { columns: 'auto', minColumnWidth: '14rem', gap: 4 });const MEMBERS = [ { name: 'Ada Kowalski', role: 'Engineering lead', status: 'online' }, { name: 'Bruno Silva', role: 'Site reliability', status: 'busy' }, { name: 'Chen Wei', role: 'Backend engineer', status: 'away' }, { name: 'Divya Nair', role: 'Frontend engineer', status: 'offline' },] as const;const cards = MEMBERS.map((m) => { const content = document.createElement('div'); Flex.apply(content, { gap: 3, align: 'center' }); Avatar.create(hostIn(content), { name: m.name, status: m.status, size: 'md' }); const who = document.createElement('div'); who.append(Text.create(m.name, { strong: true }), Text.create(m.role, { tone: 'muted', size: 'sm' })); content.append(who); return Card.create(hostIn(grid), { content, variant: 'raised', headingLevel: 3 });});
// Skills and shortcuts.const details = hostIn(page);Grid.apply(details, { columns: 'auto', minColumnWidth: '16rem', gap: 4 });const skillsBody = document.createElement('div');const tags = TagGroup.create(hostIn(skillsBody), { label: 'Team skills', removable: true, selection: 'multiple', value: ['kubernetes'], items: [ { value: 'kubernetes', label: 'Kubernetes' }, { value: 'terraform', label: 'Terraform' }, { value: 'go', label: 'Go' }, { value: 'observability', label: 'Observability' }, { value: 'security', label: 'Security' }, ],});annotate(Card.create(hostIn(details), { title: 'Skills', content: skillsBody, headingLevel: 3 }).host, ['layout', 'card', 'tag-group']);
const shortcutsBody = document.createElement('dl');shortcutsBody.className = 'sc-shortcuts';for (const [keys, text] of [ ['Mod+K', 'Search'], ['Mod+Shift+P', 'Command palette'], ['?', 'Show shortcuts'],] as const) { const dt = document.createElement('dt'); Kbd.create(dt, { hotkey: keys }); const dd = document.createElement('dd'); dd.textContent = text; shortcutsBody.append(dt, dd);}annotate(Card.create(hostIn(details), { title: 'Shortcuts', content: shortcutsBody, headingLevel: 3 }).host, ['layout', 'card', 'kbd']);
const footer = annotate(hostIn(page), ['layout', 'avatar-group', 'typography']);Flex.apply(footer, { gap: 3, align: 'center', justify: 'between', wrap: true });const group = AvatarGroup.create(hostIn(footer), { label: 'Recently active', max: 4, items: ['Ada Kowalski', 'Bruno Silva', 'Chen Wei', 'Divya Nair', 'Emeka Obi', 'Farah Haddad', 'Grace Liu'].map((name) => ({ name })) });footer.append(Link.create({ href: 'https://example.com/platform', text: 'Team handbook', external: true }));
sc.listen(tags.host, ['aui-change', 'aui-remove'], 'tags');tags.host.addEventListener('aui-change', (e) => { sc.log('selected skills', (e as CustomEvent<TagGroupChangeDetail>).detail.value);});
choice( sc, 'Spacing', [ { value: '4', label: 'Compact' }, { value: '6', label: 'Comfortable' }, { value: '10', label: 'Spacious' }, ], '6', (g) => { const gap = Number(g) as 4 | 6 | 10; stack.update({ gap }); gridLayout.update({ gap: gap === 10 ? 8 : 4 }); headerFlex.update({ gap: gap === 10 ? 6 : 4 }); }, ['layout'],);choice( sc, 'Avatar shape', [ { value: 'square', label: 'Square' }, { value: 'circle', label: 'Circle' }, ], 'square', (shape) => { avatar.update({ shape }); group.update({ shape }); }, ['avatar', 'avatar-group'],);toggle(sc, 'Outline badges', false, (outline) => { for (const b of badgeList) b.update({ variant: outline ? 'outline' : 'subtle' });}, ['badge']);toggle(sc, 'Sunken cards', false, (sunken) => { for (const c of cards) c.update({ variant: sunken ? 'sunken' : 'raised' });}, ['card']);Shortcuts for the current platform
Section titled “Shortcuts for the current platform”import { Kbd } from '@absoluteui/components/kbd';
const list = document.createElement('ul');document.body.append(list);const shortcuts: [string, string][] = [['Save', 'Mod+S'], ['Command palette', 'Mod+Shift+P'], ['Close dialog', 'Esc'], ['Next row', 'ArrowDown']];for (const [command, hotkey] of shortcuts) { const item = document.createElement('li'); const keys = document.createElement('span'); item.append(`${command}: `, keys); list.append(item); Kbd.create(keys, { hotkey });}The same shortcut on Apple and other platforms
Section titled “The same shortcut on Apple and other platforms”import { Kbd } from '@absoluteui/components/kbd';
for (const platform of ['apple', 'other'] as const) { const line = document.createElement('p'); const keys = document.createElement('span'); line.append(`${platform === 'apple' ? 'macOS' : 'Windows and Linux'}: `, keys); document.body.append(line); Kbd.create(keys, { hotkey: 'Mod+Alt+Shift+K', platform });}Install and start
Section titled “Install and start”npm install @absoluteui/components @absoluteui/core @absoluteui/themeRegistry setup, the theme stylesheet, and the Content Security Policy are covered in Installation.
import { Kbd } from '@absoluteui/components/kbd';import '@absoluteui/components/kbd/style.css';First use
Section titled “First use”import { Kbd } from '@absoluteui/components/kbd';import '@absoluteui/components/kbd/style.css';
const host = document.querySelector<HTMLElement>('#palette-shortcut');if (host) Kbd.create(host, { hotkey: 'Mod+Shift+P' });More usage
import { Kbd } from '@absoluteui/components/kbd';import { matchesHotkey } from '@absoluteui/utilities';
const SAVE = 'Mod+S';const hint = document.querySelector<HTMLElement>('#save-shortcut');if (hint) Kbd.create(hint, { hotkey: SAVE });document.addEventListener('keydown', (event) => { if (matchesHotkey(event, SAVE)) event.preventDefault();});Using Angular? See Kbd for Angular.
API reference
Section titled “API reference”Factory
Section titled “Factory”Kbd.create(host: HTMLElement, options: KbdOptions): KbdGlobal configuration key: kbd (see Configuration).
Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
hotkey |
string |
Shortcut in matchesHotkey syntax, such as ‘Mod+Shift+K’; ‘Plus’ is the + key. Required. | |
platform |
'auto' | 'apple' | 'other' |
"auto" |
Apple shows Command for Mod and modifier symbols; other shows Ctrl and ‘+’ separators; auto detects. Globally configurable. |
size |
'sm' | 'md' |
"md" |
Keycap size. Globally configurable. |
locale |
string |
"en-US" |
Locale of key names. Globally configurable. Inherited from common configuration. |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
host |
HTMLElement |
The host element (receives the classes). |
hotkey |
string |
Current hotkey string. |
text |
string |
The visible shortcut text for the resolved platform. |
options |
Readonly<KbdOptions> |
Current options. |
Methods
Section titled “Methods”| Method | Description |
|---|---|
update(options: Partial<KbdOptions>): void |
Merge and apply options. |
destroy(): void |
Remove rendering, classes, and the configuration subscription. |
CSS classes
Section titled “CSS classes”All rules live in the aui.components cascade layer, so application styles override them without specificity battles.
| Class | Purpose |
|---|---|
aui-kbd |
Host. |
aui-kbd--sm | --md |
Size modifiers. |
aui-kbd__combo |
Outer kbd element for the combination. |
aui-kbd__key |
One keycap (kbd). |
aui-kbd__separator |
‘+’ between keycaps (not on Apple platforms). |
Design tokens
Section titled “Design tokens”Tokens this stylesheet reads (verified in CI). Override them in a theme or with the Theme Designer.
--aui-border-width | --aui-color-border-strong | --aui-color-surface-sunken | --aui-color-text | --aui-color-text-muted | --aui-font-family-mono | --aui-font-family-sans | --aui-font-size-sm | --aui-font-size-xs | --aui-line-height-tight | --aui-radius-sm | --aui-space-1
TypeScript definitions
type KbdPlatform = 'auto' | 'apple' | 'other';type KbdSize = 'sm' | 'md';interface KbdConfig { platform: KbdPlatform; size: KbdSize }interface KbdOptions extends Partial<KbdConfig> { hotkey: string; locale?: string;}Accessibility and performance
Section titled “Accessibility and performance”Accessibility
Section titled “Accessibility”Pattern: Keyboard input markup: a kbd element for the combination with one nested kbd per key (HTML kbd semantics).
Checked on every docs build: the showcase passes axe (WCAG 2.2 A and AA rules) in the default, dark, and high-contrast themes and right to left; the playground loads without errors and passes axe before and after every on/off option is switched, with no Content Security Policy violations.
Keyboard
Section titled “Keyboard”| Key | Context | Action |
|---|---|---|
| None | Any | Not focusable; read in document order by assistive technology. |
| Element | Role |
|---|---|
| combination and keys | none (kbd text semantics) |
| symbol glyphs | none (aria-hidden=true; a visually hidden name follows) |
ARIA attributes
Section titled “ARIA attributes”| Attribute | Element | Value |
|---|---|---|
aria-hidden |
Apple modifier and arrow symbols | true; the key name is provided as visually hidden text |
Never receives or moves focus.
WCAG 2.2 success criteria addressed
Section titled “WCAG 2.2 success criteria addressed”| Criterion | Level | Note |
|---|---|---|
| 1.1.1 Non-text Content | A | |
| 1.3.1 Info and Relationships | A | |
| 1.4.3 Contrast (Minimum) | AA |
Automated test results: Accessibility and compliance.
Notes and known caveats
Section titled “Notes and known caveats”- Symbols such as the Command sign are hidden from assistive technology and replaced by localized names (‘Command’), so screen readers do not announce unknown glyphs.
- Shortcuts supplement, never replace, a visible way to reach the command.
- Manual screen-reader verification (NVDA, JAWS, VoiceOver) is pending.
Performance
Section titled “Performance”| Import cost | Minified | gzip | brotli | CSS brotli |
|---|---|---|---|---|
@absoluteui/components/kbd |
9.3 kB | 4.0 kB | 3.5 kB | 0.4 kB |
Measured at build time, including every AbsoluteUI module the component pulls in. No third-party runtime dependencies.
| Budget (enforced in CI) | Limit |
|---|---|
| Kbd.create, per instance | < 1 ms average in headless Chromium |
Tested scale: Unit-tested per instance; not data-driven.
Constant work per render: one element per key.
Measured run times: Performance.
Details
Section titled “Details”States
Platforms apple and other; sizes sm and md.
State transitions
| From | Trigger | To |
|---|---|---|
| any | update({ hotkey, platform, size, locale }) |
new keycaps |
| any | global configuration change | platform, size, and locale follow the configuration unless set on the instance |
| any | destroy() |
host restored to empty |
Accessibility notes
- Screen readers hear “Command S” rather than an unknown glyph on Apple platforms.
- A shortcut should never be the only way to reach a command.
- The e2e axe run covers three themes; manual screen-reader verification is pending.
Responsive behavior
Keycaps in one combination do not wrap; the combination wraps as a unit with surrounding text.
Right-to-left
Key order follows the hotkey string in both directions; shortcuts are not mirrored.
Theming
color-text on --aui-kbd-bg is in the contrast gate. Keycaps have a thicker bottom border. Forced-colors mode draws CanvasText borders.
Global configuration
configureAbsoluteUI({ components: { kbd: { platform: 'apple', size: 'sm' } } });Component configuration
Instance options override global and theme configuration. Configuration changes re-render existing instances.
Icons
None. Modifier and arrow symbols are Unicode characters, not icons.
Security
Key text uses textContent; it is never parsed as HTML. CSP-safe.
Data handling
With platform: 'auto', reads navigator.userAgent on render (the same signal as matchesHotkey). No persistence, network access, or telemetry.
Supported data scale
Not data-driven.
Edge cases
- One combination per instance: show a sequence (“G then I”) as one Kbd per step.
Ctrl+Plusshows the + key;Ctrl++is rejected.- On Apple platforms both
ModandMetashow Command, andCtrlshows Control. - Safe in renderers that discard nodes without calling
destroy(), such as Data Table cells: the configuration subscription holds the instance weakly, so a discarded shortcut is released.
Errors
| Code | Category | Cause |
|---|---|---|
KBD_OPTIONS |
configuration | Missing hotkey, an empty part ('Ctrl+'), or an unknown platform. |
CFG_INVALID_VALUE / CFG_UNKNOWN_OPTION |
configuration | Invalid platform, size, or locale configuration. |
Invalid options throw before the host is modified; an invalid update() leaves the previous state intact.
Known limitations
- Platform detection with
autouses the user-agent string; setplatformwhen it is known. - Manual screen-reader verification is pending.
Unsupported scenarios
- Listening for key presses: use
matchesHotkey. - HTML or
Nodecontent.
(c) 2026 Kasadara Technology Solutions Pvt Ltd. AbsoluteUI is free to use under the AbsoluteUI Free Use License; it is not open source.