shadcn.io is not affiliated with official shadcn/ui
Kbd examples · Pressed State
Pressed Down Kbd for React
A ⌘K shortcut whose Command key sits lower, as if pressed down.
A real key moves when you press it. This React example moves the Command key of a ⌘K KbdGroup down by two pixels with translate-y-0.5, so it sits a little below K, as if held down. The color doesn't change: the offset alone suggests the press.
Preview
Installation
FAQ
When should keys show a pressed-down effect?
In shortcut trainers and on-screen keyboards that react to the keys the user presses, and in step-by-step tutorials that show which key to hold. In static documentation, leave every key flat.
How does translate-y create the pressed effect?
translate-y-0.5 moves the cap down by two pixels without affecting the layout around it, so the next key doesn't shift. The Kbd has no shadow, so there's nothing to remove; if you add a shadow to your caps, drop it on the pressed one to make it look flush.
How long should the pressed state last?
As long as the key is held. In an interactive demo, add the class on keydown and remove it on keyup; in a static illustration it stays on.
Can several keys look pressed at once?
Yes, that's how a chord works: ⌘ goes down, then K. Put the class on each key that's held, and the caps that aren't stay up.
Related
- Active State KbdA ⌘K shortcut whose Command key is filled
- 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