Browse components · Kbd
Start here
DocsDisplay
Kbd
Round typewriter keys for shortcuts.
Search⌘K
New letterCtrlN
Install
$ npx shadcn@latest add @ephemera/kbd$ npx shadcn@latest add https://ephemera.kerrshift.com/r/kbd.jsonInstalls the component, its Radix dependency and the paper theme if you don't have it yet. Prefer copying? The full source is below.
Usage
example.tsx
import { Kbd, KbdGroup } from "@/components/ui/kbd";
<KbdGroup>
<Kbd>⌘</Kbd>
<Kbd>K</Kbd>
</KbdGroup>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | Key label. |
Any other props are passed to the root element.
Fonts
Installed automatically with the paper theme: Fraunces (--font-display), IBM Plex Mono (--font-receipt), Courier Prime (--font-type), Caveat (--font-hand) and Anton (--font-stamp). Override any of those variables to use your own fonts.
Source
components/ui/kbd.tsx
import * as React from "react";
/** A round typewriter key. */
export function Kbd({ className = "", style, ...props }: React.HTMLAttributes<HTMLElement>) {
return (
<kbd
className={`inline-flex h-[26px] min-w-[26px] items-center justify-center rounded-full border-[1.5px] border-(--ink) bg-(--paper-raised) px-1.5 text-[11px] font-bold uppercase leading-none text-(--ink) ${className}`}
style={{
fontFamily: "var(--font-type, 'Courier New', ui-monospace, monospace)",
boxShadow: "inset 0 0 0 2px var(--paper-raised), inset 0 0 0 3px var(--edge), 0 2px 0 var(--ink)",
...style,
}}
{...props}
/>
);
}
export function KbdGroup({ className = "", ...props }: React.HTMLAttributes<HTMLSpanElement>) {
return <span className={`inline-flex items-center gap-1 ${className}`} {...props} />;
}