1. docs
  2. components
  3. kbd

KBD

Display keyboard key


KBD

The <kbd> element represents user input and output, typically used for keyboard input.

+ Shift + M

Installation

Copy and paste the following code into your project.

"use client";

import { cn } from "@/lib/utils";
import { Keyboard } from "react-aria-components";
import { tv, VariantProps } from "tailwind-variants";

const KbdStyles = tv({
  base: "text-xs tracking-widest text-foreground",
  variants: {
    variant: {
      filled: "bg-zinc-800/10 dark:bg-zinc-800 p-1.5  rounded",
      outline:
        "px-2 py-1 border rounded-md border-b-[3px] border-zinc-300 dark:border-zinc-800",
    },
  },
  defaultVariants: {
    variant: "filled",
  },
});

type KbdProps = React.HTMLAttributes<HTMLElement> &
  VariantProps<typeof KbdStyles>;

const Kbd = ({ variant, className, ...props }: KbdProps) => {
  return (
    <Keyboard className={cn(KbdStyles({ variant }), className)} {...props} />
  );
};

export type { KbdProps };
export { Kbd, KbdStyles };

Update the import paths to match your project setup.

Usage

The KBD component is a container that displays a keyboard key.

<Kbd variant="outline">⌘</Kbd> + <Kbd>Shift</Kbd> + <Kbd>M</Kbd>;

Props

Variants

The KBD component supports the following variants: outline and filled The default variant is filled

+ Shift
+ Shift