Kbd
Shows a keyboard key or a shortcut as a small key cap, for help text, tooltips and command menus.
size
variant
<Kbd size="md" variant="default">Esc</Kbd>When to use
- To teach a shortcut next to the action it triggers: “Buscar processo” with
CtrlK. - Inside tooltips, menu items and the footer of a command menu.
- In help text that tells the operator which key to press.
When not to use
- Buttons the user clicks. Use Button. A key cap looks pressable but does nothing.
- Status or category labels. Use Tag or Badge.
- Code or identifiers. Use
Typographywith theinlineCodevariant.
Variants
defaultoutline
| Variant | Use for |
|---|---|
default |
Filled key cap. The usual choice on plain backgrounds. |
outline |
Border only. Use it on filled or colored surfaces. |
Sizes
md · 28pxsm · 24pxxs · 20px
| Size | Height | Use for |
|---|---|---|
md |
28px | Default. Help text and empty states. |
sm |
24px | Tooltips and menu items. |
xs |
20px | Dense toolbars and table footers. |
Examples
Shortcut combinations
Put each key in its own Kbd. Use an icon with an aria-label for keys that have a symbol.
CtrlKBuscar processo pelo número
Navegar entre as tarefas
Abrir a tarefa selecionada
Content
- Write key names as they appear on the keyboard:
Esc,Enter,Ctrl,Tab. - One
Kbdper key. Never put “Ctrl + K” in a single key cap. - Describe the action in words next to the keys. The key cap alone does not say what happens.
Accessibility
- Renders the native
kbdelement, which marks the text as keyboard input for assistive technology. - It is not focusable and has no role. Do not use it as a control.
- An icon inside
Kbdis not read. Addaria-labelto theKbd(“Seta para cima”) andaria-hiddento the icon. - Keep the text description of the action beside the shortcut. Not everyone sees or uses the key.
Code
import { Kbd } from "@repo/ui/kbd";
<span className="flex items-center gap-1">
<Kbd>Ctrl</Kbd>
<Kbd>K</Kbd>
</span>;
Props
Kbd| Prop | Type | Default | Description |
|---|---|---|---|
size | "md" | "sm" | "xs" | md | Height, padding and type size |
variant | "default" | "outline" | default | Filled key cap or border only |
Kbd also accepts every attribute of the native kbd element.
Known issues
| Issue | Effect |
|---|---|
xs uses text-[0.6875rem] (11px) and sm uses text-[0.75rem] with a line height of 12px. |
Small text for operators who work 8 hours a day. Prefer md for help text. |