KBD
Display keyboard key
KBD
The <kbd>
element represents user input and output, typically used for keyboard input.
Preview
Code
⌘ + Shift + M
Installation
Copy and paste the following code into your project.
kbd.tsx
"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.
Props
Variants
The KBD
component supports the following variants: outline
and filled
The default variant is filled
Preview
Code
⌘ + Shift
⌘ + Shift