Skip to content
Primitives

Kbd

Canonical keyboard-key display (⌘ K). Compose several for a chord; pairs with the Command menu.

Motionnone

Install

Install Kineto and follow the theme setup once in your app.

bash
npm install kineto
tsx
import { Kbd, kbdVariants } from "kineto/kbd";

Preview

⌘K⇧⌘PEscEnter
tsx
import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "@/lib/cn";

const kbdVariants = cva(
  "inline-flex select-none items-center justify-center gap-1 rounded border border-border border-b-2 bg-muted font-mono font-medium text-muted-foreground shadow-xs",
  {
    variants: {
      size: {
        sm: "h-5 min-w-5 px-1 text-[10px]",
        md: "h-6 min-w-6 px-1.5 text-xs",
        lg: "h-7 min-w-7 px-2 text-sm",
      },
    },
    defaultVariants: {
      size: "md",
    },
  }
);

export interface KbdProps
  extends React.HTMLAttributes<HTMLElement>,
    VariantProps<typeof kbdVariants> {}

/**
 * Canonical keyboard-key display — `⌘`, `K`, `Esc`. Compose several for a chord
 * (`<Kbd>⌘</Kbd><Kbd>K</Kbd>`); pairs naturally with the Command menu.
 */
const Kbd = React.forwardRef<HTMLElement, KbdProps>(({ className, size, ...props }, ref) => (
  <kbd ref={ref} className={cn(kbdVariants({ size }), className)} {...props} />
));
Kbd.displayName = "Kbd";

export { Kbd, kbdVariants };

src/components/ui/kbd.tsx

Props

PropTypeDefaultDescription
size"sm" | "md" | "lg""md"Key size.