The <Kbd> component renders keyboard shortcuts using the semantic <kbd> element. It handles platform-specific formatting. Mac uses symbols with no separator, other platforms
use full names with +.
keysmod, ctrl, alt, shift, meta) are recognized and
formatted for the current platform.sizesmallsmall, medium, large. Any CSS font-size value (e.g. "14px", "1rem") is also accepted as a custom size.<Kbd keys="s" size="small" />
<Kbd keys="s" size="medium" />
<Kbd keys="s" size="large" />
<Kbd keys="s" size="1.2rem" /><Kbd keys="s" />
<Kbd keys="Enter" />
<Kbd keys="Escape" />Use mod for the platform's primary modifier — ⌘ on Mac, Ctrl elsewhere. Use ctrl for literal Control on all platforms.
<Kbd keys={['mod', 's']} />
<Kbd keys={['mod', 'shift', 'k']} />
<Kbd keys={['ctrl', 's']} />
<Kbd keys={['alt', 'F4']} />Pair a single-letter shortcut badge with a button using the start snippet. The badge sizes
to a square for single characters.
<Button>
{#snippet start()}
<Kbd keys="p" />
{/snippet}
Publish
</Button>
<Button color="red">
{#snippet start()}
<Kbd keys="d" />
{/snippet}
Delete
</Button>To show the shortcut above the button label, wrap both in a flex column.
<div style="display: inline-flex; flex-direction: column; align-items: center; gap: 4px;">
<Kbd keys="p" />
<Button>Publish</Button>
</div>For a badge that overlaps the top edge of the button, use position: relative on the
wrapper and position: absolute on the <Kbd>.
<div style="position: relative; display: inline-block; margin-top: 1em;">
<Kbd style="position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);" keys="p" />
<Button>Publish</Button>
</div>modctrlaltshiftmetaOn Mac, modifiers are shown as symbols with no separator and in canonical order (Control → Option
→ Shift → Command). On other platforms, full names are joined with +.
<!-- Mac: ⇧⌘K -->
<!-- Other: Shift + Ctrl + K -->
<Kbd keys={['mod', 'shift', 'k']} />The component adds an aria-label that spells out symbols as words, so screen readers
announce "Shift plus Command plus K" rather than reading glyph names.