Controls and surfaces
kbd
A key cap for showing a keyboard key or a shortcut.
When to use it
Naming a key the reader can press: in a menu item, a tooltip, a hint under a field. Wrap a combination in KbdGroup, one Kbd per key.
See it working
The demonstration the browser checks drive, with the keyboard as well as the pointer. More of it is on the Display page.
Card
Usage
Example figures, this month
62% of the plan used
Stat
Visitors
12,480
+8.2%than last month
Errors
31
−4than last week
Badge, avatar, kbd
SolidSoftOutlineLiveReviewFailed
AKHMRW
CtrlKLoadingor
Alert and empty state
Heads up
Billing moves to the first of the month.
Payment failed
Update the card to keep the site online.
No projects yet
Create one to see it here.
Table
| Name | Plan | Seats | Status |
|---|---|---|---|
| Example Studio | Team | 12 | Active |
| Example Bakery | Solo | 1 | Trial |
| Example Travel | Company | 48 | Active |
Add it
npx shadcn@latest add @rivier-ui/kbdThe registry is named once in components.json: see Installation.
Example
Import it from @/components/ui/kbd.
<Kbd>Esc</Kbd>
<KbdGroup>
<Kbd>Ctrl</Kbd>
<Kbd>K</Kbd>
</KbdGroup>What it needs
Plain markup: it can stay a server component. No packages beyond React.
It imports
Source
The whole file. Once copied it is yours: the registry item holds the same text.
/**
* @name kbd
* @category ui
* @description A key cap for showing a keyboard key or a shortcut.
* @when Naming a key the reader can press: in a menu item, a tooltip, a hint under a field. Wrap a combination in KbdGroup, one Kbd per key.
* @example
* <Kbd>Esc</Kbd>
* <KbdGroup>
* <Kbd>Ctrl</Kbd>
* <Kbd>K</Kbd>
* </KbdGroup>
*/
import type { ComponentProps } from "react";
import { cn } from "@/lib/cn";
export function Kbd({ className, ...props }: ComponentProps<"kbd">) {
return (
<kbd
data-slot="kbd"
className={cn(
"inline-flex h-5 min-w-5 items-center justify-center rounded-control border border-border-strong bg-muted px-1 font-mono text-xs font-medium whitespace-nowrap text-foreground [&_svg]:size-3",
className,
)}
{...props}
/>
);
}
/** Keys pressed together. Renders an outer kbd, which is the correct markup for a combination. */
export function KbdGroup({ className, ...props }: ComponentProps<"kbd">) {
return <kbd data-slot="kbd-group" className={cn("inline-flex items-center gap-1 font-mono", className)} {...props} />;
}