- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Card
- Checkbox
- Collapsible
- Combobox
- Context Menu
- Date Picker (Lite)
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP (Lite)
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
import { Kbd, KbdGroup } from "@/components/ui/kbd"
export default function KbdDemo() {
return (
<div class="flex flex-col items-center gap-4">
<KbdGroup>
<Kbd>⌘</Kbd>
<Kbd>⇧</Kbd>
<Kbd>⌥</Kbd>
<Kbd>⌃</Kbd>
</KbdGroup>
<KbdGroup>
<Kbd>Ctrl</Kbd>
<span>+</span>
<Kbd>B</Kbd>
</KbdGroup>
</div>
)
}Installation
pnpm dlx shadcnui-hono-jsx@latest add kbdnpx shadcnui-hono-jsx@latest add kbdyarn dlx shadcnui-hono-jsx@latest add kbdbunx shadcnui-hono-jsx@latest add kbdUsage
import { Kbd } from "@/components/ui/kbd"<Kbd>Ctrl</Kbd>Composition
Use the following composition to build Kbd and KbdGroup:
Kbd
KbdGroup
├── Kbd
└── KbdGroup
Use the KbdGroup component to group keyboard keys together.
Use Ctrl + BCtrl + K to open the command palette
import { Kbd, KbdGroup } from "@/components/ui/kbd"
export default function KbdGroupExample() {
return (
<div class="flex flex-col items-center gap-4">
<p class="text-sm text-muted-foreground">
Use{" "}
<KbdGroup>
<Kbd>Ctrl + B</Kbd>
<Kbd>Ctrl + K</Kbd>
</KbdGroup>{" "}
to open the command palette
</p>
</div>
)
}Button
Use the Kbd component inside a Button component to display a keyboard key inside a button.
import { Button } from "@/components/ui/button"
import { Kbd } from "@/components/ui/kbd"
export default function KbdButton() {
return (
<Button variant="outline">
Accept{" "}
<Kbd data-icon="inline-end" class="translate-x-0.5">
⏎
</Kbd>
</Button>
)
}Tooltip
You can use the Kbd component inside a Tooltip component to display a tooltip with a keyboard key.
import { Button } from "@/components/ui/button"
import { ButtonGroup } from "@/components/ui/button-group"
import { Kbd, KbdGroup } from "@/components/ui/kbd"
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip"
export default function KbdTooltip() {
return (
<div class="flex flex-wrap gap-4">
<ButtonGroup>
<Tooltip>
<TooltipTrigger render={<Button variant="outline" />}>
Save
</TooltipTrigger>
<TooltipContent>
Save Changes <Kbd>S</Kbd>
</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger render={<Button variant="outline" />}>
Print
</TooltipTrigger>
<TooltipContent>
Print Document{" "}
<KbdGroup>
<Kbd>Ctrl</Kbd>
<Kbd>P</Kbd>
</KbdGroup>
</TooltipContent>
</Tooltip>
</ButtonGroup>
</div>
)
}Input Group
You can use the Kbd component inside a InputGroupAddon component to display a keyboard key inside an input group.
import { SearchIcon } from "@/components/icons"
import {
InputGroup,
InputGroupAddon,
InputGroupInput,
} from "@/components/ui/input-group"
import { Kbd } from "@/components/ui/kbd"
export default function KbdInputGroup() {
return (
<div class="flex w-full max-w-xs flex-col gap-6">
<InputGroup>
<InputGroupInput placeholder="Search..." />
<InputGroupAddon>
<SearchIcon />
</InputGroupAddon>
<InputGroupAddon align="inline-end">
<Kbd>⌘</Kbd>
<Kbd>K</Kbd>
</InputGroupAddon>
</InputGroup>
</div>
)
}RTL
To enable RTL support in shadcn/ui, see the RTL configuration guide.
// This example sets dir and uses useTranslation because this site is not RTL.
// In an RTL app you won't need them; see the RTL guide.
import {
type Translations,
useTranslation,
} from "@/components/language-selector"
import { Kbd, KbdGroup } from "@/components/ui/kbd"
const translations: Translations = {
en: {
dir: "ltr",
values: {},
},
ar: {
dir: "rtl",
values: {},
},
he: {
dir: "rtl",
values: {},
},
}
export function KbdRtl() {
const { dir } = useTranslation(translations, "ar")
return (
<div class="flex flex-col items-center gap-4" dir={dir}>
<KbdGroup>
<Kbd>⌘</Kbd>
<Kbd>⇧</Kbd>
<Kbd>⌥</Kbd>
<Kbd>⌃</Kbd>
</KbdGroup>
<KbdGroup>
<Kbd>Ctrl</Kbd>
<span>+</span>
<Kbd>B</Kbd>
</KbdGroup>
</div>
)
}Notes
- Accepts
classinstead ofclassName. - Upstream documentation: shadcn/ui Kbd. See also Differences from shadcn/ui.
API Reference
Kbd
Use the Kbd component to display a keyboard key.
| Prop | Type | Default |
|---|---|---|
className | string | `` |
<Kbd>Ctrl</Kbd>KbdGroup
Use the KbdGroup component to group Kbd components together.
| Prop | Type | Default |
|---|---|---|
className | string | `` |
<KbdGroup>
<Kbd>Ctrl</Kbd>
<Kbd>B</Kbd>
</KbdGroup>