Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Kbd examples · Sizes

Inline with Text Kbd for React

⌘ and K keys inline in a sentence about the command palette.

Framework
UI library

Shortcuts are often taught in a sentence: Press ⌘ K to open the command palette. This React example puts two Kbd caps straight into a small paragraph, with spaces between the words and the keys. Kbd is an inline element, so it sits on the line with the text around it.

Preview

Preview width

Press ⌘ K to open the command palette

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

Should inline key caps match the surrounding text size?

Close to it. The Kbd's extra-small type sits well in small text like this paragraph. In larger body text, the caps read a bit smaller than the words, which is fine; if they look too small, raise their text size one step.

How should inline key caps be spaced?

Ordinary spaces in the text, as here, are enough between a word and a cap. To keep the keys of one shortcut tight together, put them in a KbdGroup instead of separating them with spaces.

When should I use separate Kbd caps instead of a KbdGroup?

A KbdGroup marks the keys as one shortcut pressed together and spaces them evenly. Separate caps in the text read as separate keys. For a chord like ⌘K, a KbdGroup inside the sentence is usually clearer.

Are inline key caps accessible?

Yes. Kbd renders a kbd element, and screen readers read its text as part of the sentence. A symbol like ⌘ may be read as a symbol name or skipped, so for important instructions add the key's name as visually hidden text.

Should inline key caps look different from standalone ones?

Usually not: the same cap in a sentence and next to a menu item helps people recognize shortcuts. If the caps look heavy in long text, a lighter fill on them is enough.

What happens when a shortcut wraps to the next line?

Separate caps can end up on different lines, splitting ⌘ from K. A KbdGroup doesn't wrap inside, so put chords in one to keep them together.