Skip to content
All components
Primitives

Kbd

Show the keys of a keyboard shortcut that the application actually supports, inline with text or next to an action.

A keyboard key, and a group of them.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add kbd

Then import it from @/components/ui/kbd. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Shortcut

Combine key labels to explain a keyboard shortcut. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Kbd, KbdGroup } from "@/components/ui/kbd"

export function KbdShortcut() {
  return (
    <div className="flex flex-col items-center gap-3 text-paragraph-sm text-sub-600">
      <p className="flex items-center gap-2">
        Open the palette with
        <KbdGroup>
          <Kbd>Ctrl</Kbd>
          <Kbd>K</Kbd>
        </KbdGroup>
      </p>
    </div>
  )
}

Single key

Display one key label without adding keyboard behavior. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

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

export function KbdSingleKey() {
  return (
    <div className="flex flex-col items-center gap-3 text-paragraph-sm text-sub-600">
      <p className="flex items-center gap-2">
        Close it with <Kbd>Esc</Kbd>
      </p>
    </div>
  )
}

Sequence

Describe a key sequence pressed one after another. Words between the keys distinguish a sequence from a simultaneous combination.

"use client"

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

export function KbdSequence() {
  return (
    <div className="flex flex-col items-center gap-3 text-paragraph-sm text-sub-600">
      <p className="flex flex-wrap items-center gap-2">
        Go to the inbox with <Kbd>G</Kbd> then <Kbd>I</Kbd>
      </p>
    </div>
  )
}

In button

Show a shortcut hint inside a button. The hint is hidden from assistive technology so the button name stays the action label.

"use client"

import { SearchIcon } from "lucide-react"

import { Button } from "@/components/ui/button"
import { Kbd, KbdGroup } from "@/components/ui/kbd"

export function KbdInButton() {
  return (
    <div className="flex flex-col items-center gap-3 text-paragraph-sm text-sub-600">
      <Button emphasis="stroke" intent="neutral">
        <SearchIcon />
        Search
        <KbdGroup aria-hidden="true">
          <Kbd>Ctrl</Kbd>
          <Kbd>K</Kbd>
        </KbdGroup>
      </Button>
    </div>
  )
}

Shortcut list

List shortcuts as a description list of actions and keys. Each action is a term and its keys are the definition, so the pairing is announced.

"use client"

import { Kbd, KbdGroup } from "@/components/ui/kbd"

const shortcuts = [
  { action: "Search", keys: ["Ctrl", "K"] },
  { action: "New document", keys: ["Ctrl", "Alt", "N"] },
  { action: "Show all shortcuts", keys: ["?"] },
]

export function KbdShortcutList() {
  return (
    <div className="flex flex-col items-center gap-3 text-paragraph-sm text-sub-600">
      <dl className="grid w-full max-w-72 grid-cols-[1fr_auto] items-center gap-x-4 gap-y-2">
        {shortcuts.map((shortcut) => (
          <div key={shortcut.action} className="contents">
            <dt>{shortcut.action}</dt>
            <dd>
              <KbdGroup>
                {shortcut.keys.map((key) => (
                  <Kbd key={key}>{key}</Kbd>
                ))}
              </KbdGroup>
            </dd>
          </div>
        ))}
      </dl>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Kbd

Display the notation of a keyboard shortcut.

Kbd props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
Kbd inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

KbdGroup

Group related parts while preserving the parent component's required composition.

KbdGroup props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
KbdGroup inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLSpanElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLSpanElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLSpanElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLSpanElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLSpanElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

Accessibility & usage

From registry/ui/kbd.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Teaching a shortcut in help text, onboarding or empty states: 'Open the palette with Ctrl K'.
  • A shortcut hint inside a menu item, command palette row or search button.
  • A shortcut reference panel that lists actions and their keys.

When not to use

  • To register or handle a shortcut; Kbd only renders notation and binds nothing.
  • For shortcuts the product has not implemented or that differ by platform and are not adapted.
  • As decoration for non-keyboard content such as tags or codes; use Badge or inline code instead.

Anatomy

Kbd
A native <kbd> element styled as a keycap. One key per Kbd.
KbdGroup
An inline span that spaces several Kbd elements for a key combination.

Keyboard & interaction

  • Kbd and KbdGroup are passive and never focusable; there is nothing to press.
  • The shortcut behavior lives in the consumer's key handler; keep the notation and the handler in sync.
  • When a shortcut hint sits inside a button, the button keeps its own activation; the hint adds no behavior.

Responsive behavior

  • Keycaps do not wrap internally; in narrow layouts allow the surrounding text to wrap (flex-wrap) so a combination moves to the next line as a unit.
  • Shortcut hints are irrelevant on touch-only devices; hide them on small screens when they crowd the action, but keep the action itself.
  • In a shortcut list, use a two-column grid with the action shrinking and the keys auto-sized so it reflows at 320 CSS pixels.

Content guidelines

  • Write keys as printed on the keyboard: 'Ctrl', 'Alt', 'Shift', 'Esc', 'Enter', '⌘' on macOS. One key per Kbd.
  • For a combination pressed together, group the keys in KbdGroup; for a sequence, put words between them: 'G then I'.
  • Name the action first and the keys second: 'Search Ctrl K', not 'Ctrl K to search'.
  • Use the same order of modifiers everywhere (for example Ctrl, Alt, Shift, then the key).

Alternatives

  • Badge — A short status or category label that is not a key.
  • Dropdown menu — Menu items already provide DropdownMenuShortcut for shortcut hints in menus.
  • Command — Discoverable command search where shortcuts are listed next to each command.

Resources