Skip to main content
The Kbd component displays keyboard shortcuts with proper semantic HTML and includes built-in tooltips for common keyboard symbols.

Installation

npx shadcn@latest add @eo-n/kbd

Usage

import { Kbd, KbdKey, KbdSeparator } from "@/components/ui/kbd";
<Kbd>
  <KbdKey></KbdKey>
  <KbdSeparator />
  <KbdKey>Enter</KbdKey>
</Kbd>

Examples

Basic Shortcut

<Kbd>
  <KbdKey></KbdKey>
  <KbdSeparator />
  <KbdKey>K</KbdKey>
</Kbd>

With Predefined Tooltips

The component automatically shows descriptive tooltips for common keyboard symbols:
<Kbd>
  <KbdKey></KbdKey> {/* Shows "Return" on hover */}
</Kbd>

<Kbd>
  <KbdKey></KbdKey> {/* Shows "Control" on hover */}
  <KbdSeparator />
  <KbdKey>C</KbdKey>
</Kbd>

Custom Tooltips

<Kbd>
  <KbdKey title="Control"></KbdKey>
  <KbdSeparator />
  <KbdKey title="Shift"></KbdKey>
  <KbdSeparator />
  <KbdKey title="Command Palette">P</KbdKey>
</Kbd>

Outline Variant

<Kbd variant="outline">
  <KbdKey>Ctrl</KbdKey>
  <KbdSeparator />
  <KbdKey>V</KbdKey>
</Kbd>

Ghost Variant

<Kbd variant="ghost">
  <KbdKey>Esc</KbdKey>
</Kbd>

Different Sizes

<Kbd size="sm">
  <KbdKey></KbdKey>
  <KbdSeparator />
  <KbdKey>S</KbdKey>
</Kbd>

<Kbd size="default">
  <KbdKey></KbdKey>
  <KbdSeparator />
  <KbdKey>S</KbdKey>
</Kbd>

<Kbd size="lg">
  <KbdKey></KbdKey>
  <KbdSeparator />
  <KbdKey>S</KbdKey>
</Kbd>

Component API

Kbd

The root container for the keyboard shortcut.
variant
'default' | 'outline' | 'ghost'
The visual style variant.
  • default - Accent background
  • outline - Border with background
  • ghost - Transparent with no shadow
size
'sm' | 'default' | 'lg'
The size of the keyboard shortcut display.
asChild
boolean
When true, merges props into the immediate child element.
className
string
Additional CSS classes.

KbdKey

Represents an individual keyboard key.
title
string
Custom tooltip text. If not provided, uses predefined descriptions for common symbols.
asChild
boolean
When true, merges props into the immediate child element.
children
React.ReactNode
required
The key content (symbol or text).

KbdSeparator

A visual separator between keys.
children
React.ReactNode
The separator character. Defaults to ”+”.
asChild
boolean
When true, merges props into the immediate child element.

Predefined Key Descriptions

The following symbols have built-in tooltip descriptions:
  • - Command
  • - Shift
  • - Option
  • - Control
  • - Backspace
  • - Escape
  • - Return
  • - Tab
  • - Enter
  • - Arrow keys
  • - Caps Lock
  • - Delete
  • - Page Up/Down
  • - Home/End

Build docs developers (and LLMs) love