Bloom Logo

Kbd

A tactile keyboard key indicator component used to display keyboard shortcuts and hotkeys.

kbd.tsx

Kbd key indicator component with size variants.

ReactTailwindUI ComponentKeyboardShortcut
import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";

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

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

const Kbd = React.forwardRef<HTMLElement, KbdProps>(
  ({ className, size, children, ...props }, ref) => {
    return (
      <kbd
        ref={ref}
        className={cn(kbdVariants({ size, className }))}
        {...props}
      >
        {children}
      </kbd>
    );
  }
);
Kbd.displayName = "Kbd";

export { Kbd, kbdVariants };

Basic Usage

Display single or combined keyboard keys.

K
CtrlShiftP
AltF4

Sizes

Kbd supports sm, md (default), and lg size variants.

size: sm | md | lg
Small (⌘K)Medium (⌘K)Large (⌘K)
API Reference

Props — Kbd

Properties for configuring the Kbd component.

PropTypeDefaultDescription
size'sm' | 'md' | 'lg''md'Size variant controlling height, padding, and font size.
classNamestringAdditional CSS classes to override default key styles.