Skip to content

Now in the official shadcn registry directory.

Start free

Kbd

A keyboard key hint in the mono font on the surface tokens. Combine several for shortcut chords.

display
A free styled version is available

Press Ctrl + K to open the command palette.

Installation

Run the following command

npx shadcn@latest add @ai2/kbd

The @ai2/tokens theme and the component file are installed together.

Usage

TS
import { Kbd } from "@/components/ui/kbd"

<Kbd>Ctrl</Kbd> + <Kbd>K</Kbd>

Render one Kbd per key and combine them for chords. The element is pointer-events-none by design: it is a hint, not a button.

Examples

Key combinations

Ctrl + K

Shift P

Esc

Inline in text

Press / to focus the search field, use to move through results and Enter to open one.

Props

Kbd has no props of its own. It accepts every native <kbd> prop, and className for size or color overrides.

ai2 Kbd: keyboard shortcut hints for React, styled by tokens

The ai2 Kbd is a shadcn-compatible keyboard key component for React, styled with Tailwind CSS v4 on the shared ai2 tokens. It renders a single key cap in the mono font on the surface tokens, with a subtle keyboard-like shadow, and you compose several of them into shortcut chords like Ctrl+K / Cmd+K in menus, tooltips, command palettes and onboarding copy.

Because it ships through the shadcn registry format, you install it with one CLI command, an MCP agent, or a copy-paste, and the source lands in your own project. You own the file; there is no runtime dependency on ai2 itself. The live example above is the exact component you get.

What is the ai2 Kbd?

It is a single part: one Kbd component that renders the native <kbd> HTML element with key-cap styling: mono font, surface-2 background, a border and a one-pixel bottom shadow that reads as a physical key. There is no radix primitive and no JavaScript behavior; it is a purely presentational element.

By design it is pointer-events-none and select-none: a Kbd is a hint about a shortcut, not a button that triggers it. The minimum square size keeps single characters like K or / as tidy caps, while longer labels like Ctrl, Shift and Esc grow naturally with padding.

Why use it

  • Semantic HTML by default: It renders the native kbd element, the HTML tag defined for user keyboard input, so the markup says what the content is without any ARIA bolted on.
  • Reads as a real key: Mono font, bordered cap and a bottom shadow built from the border token give it a physical keyboard look in both light and dark mode.
  • Not a fake button: pointer-events-none and select-none make it inert: users cannot click or accidentally select a hint, so it never competes with the real shortcut handler.
  • Composes into chords: One Kbd per key, joined with + or a small gap, expresses any shortcut: Ctrl+K, Cmd+Shift+P, or a bare Esc.
  • Agent-readable metadata: The registry item describes the intended use in plain words, so an MCP agent can find, inspect and install it without guessing.

Features

  • shadcn registry install: One command adds the component and the @ai2/tokens theme to your project. Kbd has no npm dependencies of its own.
  • Native kbd element: The semantic HTML element for keyboard input, so screen readers and search engines see meaningful markup, not a styled span.
  • Token-driven surface: Background comes from surface-2 and the shadow from the border token, so the cap follows your theme automatically.
  • Square minimum size: A height of 5 with a matching min-width keeps single-character keys square while multi-character keys grow with padding.
  • Data attribute for styling: The element exposes data-slot="kbd", so you can retheme every key hint from CSS without forking the component.
  • TypeScript source: The installed file is typed and forwards every native kbd prop, including className for size or color overrides.

Production tips

  • One Kbd per key: Render Ctrl+K as two Kbd elements joined by a plus sign, not one element containing "Ctrl+K". Each cap should map to one physical key.
  • Match the visitor's platform: If you show modifier keys, detect the platform and swap Ctrl for Cmd on macOS so the hint matches the shortcut users actually press.
  • The hint is not the handler: Kbd is inert on purpose. Register the actual shortcut with a keydown listener or your command palette; the component only documents it.
  • Keep hints next to their action: Put the Kbd chord inline with the menu item, tooltip or empty state that describes the action, so users learn shortcuts in context.
  • Scale with className when needed: The default cap is sized for body text. In heroes or large empty states, raise the height and font size via className instead of nesting transforms.

Works with the rest of ai2

Kbd shines next to command surfaces. Show the Ctrl+K / Cmd+K chord that opens your ai2 Command palette, annotate items in a ai2 Dropdown Menu with their shortcuts, or pair a hint with an ai2 Tooltip on icon-only buttons.

It also fits documentation and onboarding: inline key hints in help text, shortcut tables built with Table, or a dismiss hint next to a Dialog. One token source keeps the caps consistent with the rest of your UI in both modes.

FAQs

Get new components in your inbox

Component drops, new themes and release notes. No spam, and you can unsubscribe from any email.

© 2026 ai2 design system · MIT licensed · Built with its own components