shadcn.io is not affiliated with official shadcn/ui
Kbd examples · Pressed State
Active State Kbd for React
A ⌘K shortcut whose Command key is filled with the primary color, as if held.
Tutorials and keyboard overlays sometimes need to show which key is held right now. This React example fills the Command key of a ⌘K KbdGroup with the primary color (bg-primary text-primary-foreground) and leaves K in the normal muted fill, so the eye goes to the key that's down.
Preview
Installation
FAQ
When should I show keys in an active state?
In interactive tutorials that show which key to hold next, in on-screen keyboard overlays for screen recordings, and in shortcut trainers that react to what the user presses. In static docs, every key in a shortcut is pressed together, so highlighting one is confusing.
What styling works best for an active key?
A strong fill with contrasting text, like the primary color here, reads at a glance. Keep the cap's size and shape the same as the others, so the state changes but the layout doesn't move.
Can several keys be active at once?
Yes. Put the same classes on every key that's held: a shortcut trainer would light ⌘ and then K as they go down. Compute the classes from the keys that are pressed instead of hard-coding them.
Should active keys be clickable?
No. Kbd is a label, not a control: it ignores the pointer, and screen readers don't announce it as a button. If clicking should run the command, use a Button and show the shortcut inside it.
Related
- Pressed Down KbdA ⌘K shortcut whose Command key sits
- Focus State KbdA ⌘K shortcut with a focus ring around
- Hover State Kbd⌘ and K keys that change to the accent
- Command Palette Shortcut KbdThe ⌘K shortcut that opens a command
- Key Sequence with Then KbdA Ctrl K chord, the word then, and a B
- Disabled State KbdA faded Command key with a not-allowed