Kbd Badge

Keyboard shortcut badge.

⌘ K
Tailwind CSS
<kbd class="inline-flex items-center gap-1 px-2 py-1 rounded-md border border-slate-300 border-b-2 bg-slate-50 text-xs font-mono font-semibold text-slate-600">⌘ K</kbd>

Free to use in personal and commercial projects. No attribution required.

Variants

Same component, different looks. Preview each one live and copy the code you like.

Key combo

Multi key shortcut display for command palettes and docs.

Ctrl Shift P
Tailwind CSS

Dark

Dark keys for developer tools and night mode documentation.

⌘ K
Tailwind CSS

Large

Larger key for onboarding callouts where the shortcut must be obvious.

Esc
Tailwind CSS

About this kbd badge

The kbd badge shows keyboard shortcuts: ⌘K for search, ⌘S for save, Esc to close. It mimics a physical keycap with a bottom border suggesting depth. You see it in command palettes, tooltips, and onboarding hints.

This one uses border-b-2 for the keycap edge, monospace font for the technical feel, and subtle gray tones. The ⌘ symbol renders on Mac; consider 'Ctrl K' text for Windows audiences or show both.

Kbd badges teach shortcuts without a tutorial. Place them next to the action they trigger: in buttons, menu items, and empty states. They turn hidden power-user features into discoverable ones.

The most powerful features in any app hide behind keyboard shortcuts nobody discovers: the command palette, the quick save, the vim-style navigation. A tooltip that says Search does not teach the shortcut; the kbd badge sitting next to the action does. It converts invisible efficiency into something a new user can spot and a curious one can try, which is how casual users gradually become power users.

The semantic kbd element carries the styling: inline-flex, px-2 py-1, rounded-md, border border-slate-300 with a thicker border-b-2, bg-slate-50, and font-mono text-xs font-semibold. The doubled bottom border is the entire keycap illusion: it suggests a 3D key edge with no shadow and no extra markup. The monospace font gives it the technical register users expect from key names.

Detect the platform and show the right symbols: Command-K on Mac, Ctrl+K on Windows, because wrong symbols teach wrong muscle memory. Chain multi-key shortcuts with + separators in press order (Ctrl+Shift+P). In dense menus, dim the badge slightly (opacity-70) so hints support the labels instead of outshouting them.

The mistake is cramming a four-key sequence into one tiny badge. Ctrl+Shift+Alt+S at text-xs becomes an unreadable smudge that helps nobody. Show only the primary chord inline next to the action, and document the full sequences in a shortcuts modal or help page. The badge is a hint, not a manual.

Where to use it

  • ✓ Command palette hints
  • ✓ Button shortcuts
  • ✓ Onboarding tips
  • ✓ Menu accelerators

Customization tips

Use <kbd> semantic element for correctness. Show platform-appropriate symbols (⌘ on Mac, Ctrl on Windows). Group multiple keys with + separators.

Design notes

When to use

Use it to surface keyboard shortcuts where the action lives: command palette hints, button shortcuts, and menu accelerators. Showing the keys next to the action turns hidden power-user features into discoverable ones. The keycap styling reads instantly as pressable.

What to avoid

Do not show Mac-only symbols like Command to a Windows audience without also showing Ctrl. Do not badge a shortcut that does not actually work; a dead hint is worse than none.

Accessibility

Use the semantic kbd element so assistive tech can identify it. Do not make the badge the only way to discover an action; the action itself must stay reachable by keyboard and pointer.

Frequently asked questions

What is the kbd element?

The HTML <kbd> element semantically marks keyboard input. Style it as a keycap with borders and monospace font.

Should I show Mac or Windows shortcuts?

Show the shortcut for the user's platform via JavaScript detection, or show both (⌘K / Ctrl+K). Never show only Mac symbols to Windows users.

Where should shortcut hints appear?

Next to the action: in buttons, menu items, tooltips, and empty states. They teach without interrupting.

How do I make a kbd key look like a real keyboard key?

Use a light gradient background, a 1px border with a thicker 2px bottom border, rounded corners, and a small inset shadow at the bottom. That bottom-heavy border is what sells the physical key look. This element uses border-b-2 with a subtle shadow to create exactly this effect.

Should kbd text use a monospace font?

Browsers render kbd in monospace by default, which signals 'keyboard' to readers. Keep a monospace or system font stack for the key label so it reads as a key rather than a button. Just make sure the font size is not too small, since shortcut hints are often tiny.

How do I show a two-key shortcut like Ctrl + S?

Wrap each key in its own kbd element and put a + separator between them, like <kbd>Ctrl</kbd> + <kbd>S</kbd>. Screen readers announce each key separately this way. For Mac, show the symbol form like Cmd+S only if your audience is Mac-only; otherwise spell out Ctrl, Shift, and Alt.

Customize it with our tools