Kbd
StableA small key label, such as Tab or Esc, that shows which key to press.
Also known as key hint, keyboard key, keyboard shortcut, shortcut hint
Install with npm install @tattva/ui (setup), or copy the code from the kit in Downloads.
Single keys
Press Esc to close
<p className="flex items-center gap-2 text-body leading-5">Press <Kbd>Esc</Kbd> to close</p>Put the label next to the action it triggers.
When to use it
A small key label, such as Esc or Tab, set beside the action it triggers. It is only a hint: the action must also work without the key.
Made of: Key label
Do and avoid
Press Esc to close
Ctrl + K
Do
- Put it beside words that name the action.
- Use one label per key in a combination.
- Make every shortcut also work with a mouse or tap.
- Use short names such as Esc and Tab.
Avoid
- Do not use it as a button. It does nothing when clicked.
- Do not show it on touch-only screens.
- Do not use it alone. Say what the key does.
- Do not use it for hints that are not about the keyboard.
On a phone
- It is a small label for a keyboard key, and keyboard shortcuts do not apply on a phone, so hide it there or show it only where a keyboard is likely.
- Its text is 12px on a touch screen.
Properties
| Prop | Type | Default | Description |
|---|---|---|---|
| childrenrequired | ReactNode | none | Key label, such as Tab or Esc. |
| className | string | none | Extra classes merged onto the kbd element. |
"Show code under the preview gives the code for the example on the stage."
Tokens
Change one of these and every part that uses it follows.
--surface--border-strong--fg-muted
Built in
- It is marked up as a keyboard key, and screen readers read the key name as text.
- It cannot be reached with Tab and does nothing when clicked.
What you need to do
- Put words beside it that name the action. Screen readers read only the key name.
- Make the action work with a mouse or tap too.
- Hide it on touch-only screens, where there is no keyboard.
Built toward WCAG 2.2 AA and checked automatically; no independent audit yet. Read the accessibility guide