shadcn.io is not affiliated with official shadcn/ui
Tooltips, dense sidebars and status bars don't always have room for a full-size key cap. This React example shrinks both keys of a ⌘K KbdGroup with h-4 min-w-4 text-[10px]: 16 pixels tall, at least as wide, with 10-pixel type. Kbd has no size prop, so the classes on each cap set its size.
Preview
Installation
FAQ
When should I use small key caps?
Where space is tight and the shortcut is a secondary hint: a compact tooltip, a sidebar listing many shortcuts, a status bar, a table cell. Keep the default size anywhere people need to read the shortcut to use it.
What font size works for small key caps?
10 pixels, as here, is about the smallest that stays legible for a single character. Below that, letters like K and symbols like ⌘ start to blur, especially on low-density screens.
Why h-4 and min-w-4?
h-4 sets the cap to 16 pixels tall and min-w-4 to at least 16 pixels wide, so a single character sits in a square. A longer label such as Ctrl still widens the cap to fit.
How much padding should small key caps have?
The Kbd's own small horizontal padding is enough for one character. For a word at this size, keep the padding small, such as px-1, so the cap doesn't grow taller than the text around it.
Related
- Default KbdA ⌘K shortcut at the key cap's default
- 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