Kbd
A key or a shortcut, drawn as keycaps.
Actions
Added in v0.41.0
Updated
Default
Esc
Ctrl
K
Ctrl
Shift
P
<div class="flex items-center gap-6">
{ui kbd, keys: 'Esc' /}
{ui kbd, keys: ['Ctrl', 'K'] /}
{ui kbd, keys: ['Ctrl', 'Shift', 'P'] /}
</div>
keys is one key as a string, or a shortcut as an array. Each key is a native kbd, joined by a plus that a screen reader skips. A single key does not need the element: a bare <kbd>Esc</kbd> in any text already looks the same, because the base styles draw it as a keycap. Use {ui kbd} when there is more than one key, so the plus signs and spacing come for free.
In a hint
Press
Ctrl
K
to search
<div class="flex items-center gap-4">
{ui button, title: 'Search', icon: 'search', class: 'button-outline' /}
<span class="flex items-center gap-2 text-muted">
Press {ui kbd, keys: ['Ctrl', 'K'], class: 'text-sm' /} to search
</span>
</div>
The element is em-sized, so it follows the text around it, and a text-* class on it changes the size of every key. It reads in the muted color and sits inline, which suits a hint beside a button or at the end of a menu row.