shadcn.io is not affiliated with official shadcn/ui
Most shortcut hints need a key cap that reads clearly without taking over the line. This React example groups ⌘ and K in a KbdGroup with no size classes, so both caps keep the Kbd's own size: about as tall as a line of small text, with extra-small type and a muted fill. Start here for menus, tooltips, settings pages and docs, and reach for the small or large examples only when the context calls for it.
Preview
Installation
FAQ
What is the default size of a Kbd?
Kbd has no size prop. Its classes make it 20 to 22 pixels tall depending on the style, with a matching minimum width so single characters stay square, extra-small medium-weight type and small horizontal padding. The cap grows wider to fit a word such as Ctrl.
When should I use the default size instead of custom sizing?
Almost always. The default fits menu items, tooltips, buttons, inputs and running text. Use smaller caps only where space is tight, like a dense status bar, and larger ones where the shortcut is the subject, like a hero or a tutorial.
Is the default size readable for everyone?
For a short hint next to a control, yes: the text is the same extra-small size used for labels across the components. If the shortcut is the main content of a page, or people will read it from a distance, use a larger size.
How do I change the default size across my app?
Edit the classes in your copy of the Kbd component, since it lives in your project. Changing them once updates every key cap, which is better than adding size classes at every use.
Related
- Small KbdSmall ⌘ and K key caps, 16 pixels tall
- Large KbdLarge ⌘ and K key caps, 32 pixels tall
- Inline with Text Kbd⌘ and K keys inline in a sentence about
- Extra Large KbdExtra large ⌘ and K key caps, 48 pixels
- Command Palette Shortcut KbdThe ⌘K shortcut that opens a command
- Arrow Keys Cross Pattern KbdFour arrow keys in the inverted T of a