Skip to content
shadcn.io

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.

Framework
UI library

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

Preview width
⌘K

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

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.

Should the active state animate?

A short color transition, around 100 to 150 milliseconds, softens the change; anything longer lags behind a real key press. Turn it off for people who prefer reduced motion.

How do I make the active state accessible?

Color alone doesn't reach screen readers. If the state matters, say it in text as well, for example a visually hidden held after the key name, or a live region that announces the next key to press in a tutorial.