Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Pressed Down Kbd for Svelte

A ⌘K group whose Command cap sits a couple of pixels lower, so it looks pressed, while K stays in place.

UI library: Ark UI

The ⌘ cap is nudged down. K is not. It is a picture of a press, not a key event, and the caps still ignore the pointer.

Use the offset in a keyboard diagram or one step of a lesson. A control that really toggles is a Toggle. In Svelte, Ark UI does not receive the key.

Preview

Preview width

Installation

MCP · Pro
Make your AI a shadcn expert
Your agent installs components, builds pages and restyles your app from one prompt, in Claude Code, Cursor or VS Code.
Part of Pro

Anatomy

Kbd anatomy: kbd, group

Usage

<div class="rounded-md border bg-background p-4"><KbdGroup><Kbd class="translate-y-0.5">⌘</Kbd><Kbd>K</Kbd></KbdGroup></div>

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.

Should the release be instant or animated?

A very short transition, under 100 milliseconds, feels like a key springing back; a longer one feels sluggish. Respect reduced motion by dropping the transition.

Is the pressed effect accessible?

A two-pixel shift is easy to miss, and screen readers don't see it at all. Pair it with a color change, as the Active State example does, and say what's pressed in text when it matters.

API Reference

Kbd

No extra props in this demo. The rest is on the Kbd page.