shadcn.io is not affiliated with official shadcn/ui
Kbd examples · Sizes
Inline with Text Kbd for React
⌘ and K keys inline in a sentence about the command palette.
Shortcuts are often taught in a sentence: Press ⌘ K to open the command palette. This React example puts two Kbd caps straight into a small paragraph, with spaces between the words and the keys. Kbd is an inline element, so it sits on the line with the text around it.
Preview
Installation
FAQ
Should inline key caps match the surrounding text size?
Close to it. The Kbd's extra-small type sits well in small text like this paragraph. In larger body text, the caps read a bit smaller than the words, which is fine; if they look too small, raise their text size one step.
How should inline key caps be spaced?
Ordinary spaces in the text, as here, are enough between a word and a cap. To keep the keys of one shortcut tight together, put them in a KbdGroup instead of separating them with spaces.
When should I use separate Kbd caps instead of a KbdGroup?
A KbdGroup marks the keys as one shortcut pressed together and spaces them evenly. Separate caps in the text read as separate keys. For a chord like ⌘K, a KbdGroup inside the sentence is usually clearer.
Are inline key caps accessible?
Yes. Kbd renders a kbd element, and screen readers read its text as part of the sentence. A symbol like ⌘ may be read as a symbol name or skipped, so for important instructions add the key's name as visually hidden text.
Related
- Default KbdA ⌘K shortcut at the key cap's default
- Small KbdSmall ⌘ and K key caps, 16 pixels tall
- Large KbdLarge ⌘ and K key caps, 32 pixels tall
- Command Palette Shortcut KbdThe ⌘K shortcut that opens a command
- Key Sequence with Then KbdA Ctrl K chord, the word then, and a B
- Extra Large KbdExtra large ⌘ and K key caps, 48 pixels