Kbd
shadcn-htmx/kbdFreeComponent
Inline keyboard-key badge — renders a native <kbd> for a single key, or nests one <kbd> per key inside an outer one for a shortcut like Ctrl + Shift + R. Zero JavaScript.
Live preview
live · rendered by the registry
Rendered by shadcn-htmx on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://shadcn-htmx.productdevbook.com/r/kbd.jsonSource
1/** @jsxImportSource hono/jsx */2import type { Child, PropsWithChildren } from "hono/jsx"3import { cn, type ClassValue } from "@/registry/lib/cn"45// Kbd — shadcn-htmx, htmx v4 + Tailwind v4.6//7// Native element (source of truth):8// repos/mdn/files/en-us/web/html/reference/elements/kbd/index.md9// - <kbd> denotes textual user input from a keyboard / voice / other10// text-entry device. Implicit ARIA role: "no corresponding role"11// (it's phrasing content, announced as plain text). No interaction,12// so this component ships ZERO JavaScript.13// - MDN's "Representing keystrokes within an input" pattern nests a14// <kbd> per key inside an outer <kbd> that represents the whole15// shortcut. We follow that: <KbdGroup> is the outer <kbd>, each16// <Kbd> is an inner key. A lone <Kbd> (no group) is still a valid17// single-key <kbd>.18//19// Visual styling translated from shadcn/ui's Kbd (kept on-brand with our20// theme tokens, not copied verbatim):21// repos/shadcn-ui/apps/v4/registry/new-york-v4/ui/kbd.tsx22//23// We use ONLY existing theme tokens (bg-muted / text-muted-foreground /24// border). select-none + pointer-events-none keep the key glyphs from being25// selected or clicked — they are a label, not a control.2627const kbdBase =28 "pointer-events-none inline-flex h-5 w-fit min-w-5 shrink-0 select-none items-center justify-center gap-1 " +29 "rounded-sm border bg-muted px-1 font-sans text-xs font-medium text-muted-foreground " +30 "[&_svg:not([class*='size-'])]:size-3"3132// The outer <kbd> that wraps a sequence of keys. MDN allows nesting <kbd>33// inside <kbd>; the group carries no background of its own so the inner34// keys read as discrete caps with separators (the "+" text) between them.35const kbdGroupBase = "inline-flex w-fit items-center gap-1 align-middle"3637export function kbdClasses(opts?: { class?: ClassValue }): string {38 return cn(kbdBase, opts?.class)39}4041export function kbdGroupClasses(opts?: { class?: ClassValue }): string {42 return cn(kbdGroupBase, opts?.class)43}4445type KbdProps = PropsWithChildren<{46 class?: ClassValue47 id?: string48 // Accessible name override — useful for symbol-only keys (e.g. content49 // "⌘" with ariaLabel="Command"). See aria-label on MDN.50 ariaLabel?: string51 title?: string52 // htmx attrs / data-* / aria-* flow through via {...rest}.53}>5455// A single key cap. Renders one <kbd>. Use inside <KbdGroup> for shortcuts.56export function Kbd(props: KbdProps) {57// … truncated
More from shadcn-htmx
All 83 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | shadcn-htmx | Components | Free | no deps | |
| Active Searchactive-search | shadcn-htmx | Components | Free | no deps | |
| Alertalert | shadcn-htmx | Components | Free | no deps | |
| Alert Dialogalert-dialog | shadcn-htmx | Components | Free | no deps | |
| Aspect Ratioaspect-ratio | shadcn-htmx | Components | Free | no deps | |
| Auto Gridauto-grid | shadcn-htmx | Components | Free | no deps | |
| Autocompleteautocomplete | shadcn-htmx | Components | Free | no deps | |
| Autosize Textareaautosize-textarea | shadcn-htmx | Components | Free | no deps |
