# Kbd

<FrameworkCodeSwitcher>
  <div slot="astro">
```astro
---
import { Kbd } from "@/components/starwind/kbd";
---

<div class="flex items-center gap-2">
  <span class="text-sm text-muted-foreground">Press</span>
  <Kbd>Ctrl</Kbd>
  <span class="text-sm text-muted-foreground">to continue</span>
</div>
```
  </div>
  <div slot="react">
```tsx
import { Kbd } from "@/components/starwind/kbd";

export function Example() {
  return (
    <div className="flex items-center gap-2">
      <span className="text-sm text-muted-foreground">Press</span>
      <Kbd>Ctrl</Kbd>
      <span className="text-sm text-muted-foreground">to continue</span>
    </div>
  );
}
```
  </div>
  <div slot="vue">
```vue
<script setup lang="ts">
import { Kbd } from "@/components/starwind/kbd";
</script>

<template>
  <div class="flex items-center gap-2">
    <span class="text-sm text-muted-foreground">Press</span>
    <Kbd>Ctrl</Kbd>
    <span class="text-sm text-muted-foreground">to continue</span>
  </div>
</template>
```
  </div>
</FrameworkCodeSwitcher>

## Installation

```bash
npx starwind@latest add kbd --framework astro
```
</DocsTabsContent>
```bash
npx starwind@latest add kbd --framework react
```
</DocsTabsContent>
```bash
npx starwind@latest add kbd --framework vue
```
</DocsTabsContent>
</DocsTabs>

## Usage

<FrameworkCodeSwitcher>
  <div slot="astro">
```astro
---
import { Kbd } from "@/components/starwind/kbd";
---

<div class="flex items-center gap-2">
  <span class="text-sm text-muted-foreground">Press</span>
  <Kbd>Ctrl</Kbd>
  <span class="text-sm text-muted-foreground">to continue</span>
</div>
```
  </div>
  <div slot="react">
```tsx
import { Kbd } from "@/components/starwind/kbd";

export function Example() {
  return (
    <div className="flex items-center gap-2">
      <span className="text-sm text-muted-foreground">Press</span>
      <Kbd>Ctrl</Kbd>
      <span className="text-sm text-muted-foreground">to continue</span>
    </div>
  );
}
```
  </div>
  <div slot="vue">
```vue
<script setup lang="ts">
import { Kbd } from "@/components/starwind/kbd";
</script>

<template>
  <div class="flex items-center gap-2">
    <span class="text-sm text-muted-foreground">Press</span>
    <Kbd>Ctrl</Kbd>
    <span class="text-sm text-muted-foreground">to continue</span>
  </div>
</template>
```
  </div>
</FrameworkCodeSwitcher>

## Composition

Use `KbdGroup` when a shortcut contains more than one key:

```text
KbdGroup
├── Kbd
└── Kbd
```

## Basic

<FrameworkCodeSwitcher>
  <div slot="astro">
```astro
---
import { Kbd } from "@/components/starwind/kbd";
---

<Kbd>Ctrl</Kbd>
<Kbd>Shift</Kbd>
<Kbd>Alt</Kbd>
<Kbd>⌘</Kbd>
<Kbd>⏎</Kbd>
<Kbd>Esc</Kbd>
```
  </div>
  <div slot="react">
```tsx
import { Kbd } from "@/components/starwind/kbd";

export function Example() {
  return (
    <>
      <Kbd>Ctrl</Kbd>
      <Kbd>Shift</Kbd>
      <Kbd>Alt</Kbd>
      <Kbd>⌘</Kbd>
      <Kbd>⏎</Kbd>
      <Kbd>Esc</Kbd>
    </>
  );
}
```
  </div>
  <div slot="vue">
```vue
<script setup lang="ts">
import { Kbd } from "@/components/starwind/kbd";
</script>

<template>
  <Kbd>Ctrl</Kbd>
  <Kbd>Shift</Kbd>
  <Kbd>Alt</Kbd>
  <Kbd>⌘</Kbd>
  <Kbd>⏎</Kbd>
  <Kbd>Esc</Kbd>
</template>
```
  </div>
</FrameworkCodeSwitcher>

## Group

Use the `KbdGroup` component to group keyboard keys together.

<FrameworkCodeSwitcher>
  <div slot="astro">
```astro
---
import { Kbd, KbdGroup } from "@/components/starwind/kbd";
---

<p class="text-sm text-muted-foreground">
  Use{" "}
  <KbdGroup>
    <Kbd>Ctrl</Kbd>
    <span>+</span>
    <Kbd>K</Kbd>
  </KbdGroup>
  {" "}to open the command palette
</p>

<p class="text-sm text-muted-foreground">
  Press{" "}
  <KbdGroup>
    <Kbd>⌘</Kbd>
    <span>+</span>
    <Kbd>Shift</Kbd>
    <span>+</span>
    <Kbd>P</Kbd>
  </KbdGroup>
  {" "}to open command palette
</p>
```
  </div>
  <div slot="react">
```tsx
import { Kbd, KbdGroup } from "@/components/starwind/kbd";

export function Example() {
  return (
    <>
      <p className="text-sm text-muted-foreground">
        Use{" "}
        <KbdGroup>
          <Kbd>Ctrl</Kbd>
          <span>+</span>
          <Kbd>K</Kbd>
        </KbdGroup>
        {" "}to open the command palette
      </p>

      <p className="text-sm text-muted-foreground">
        Press{" "}
        <KbdGroup>
          <Kbd>⌘</Kbd>
          <span>+</span>
          <Kbd>Shift</Kbd>
          <span>+</span>
          <Kbd>P</Kbd>
        </KbdGroup>
        {" "}to open command palette
      </p>
    </>
  );
}
```
  </div>
  <div slot="vue">
```vue
<script setup lang="ts">
import { Kbd, KbdGroup } from "@/components/starwind/kbd";
</script>

<template>
  <p class="text-sm text-muted-foreground">
    Use
    <KbdGroup>
      <Kbd>Ctrl</Kbd>
      <span>+</span>
      <Kbd>K</Kbd>
    </KbdGroup>
    to open the command palette
  </p>

  <p class="text-sm text-muted-foreground">
    Press
    <KbdGroup>
      <Kbd>⌘</Kbd>
      <span>+</span>
      <Kbd>Shift</Kbd>
      <span>+</span>
      <Kbd>P</Kbd>
    </KbdGroup>
    to open command palette
  </p>
</template>
```
  </div>
</FrameworkCodeSwitcher>

## With Button

Use the `Kbd` component inside a `Button` component to display a keyboard key inside a button.

<FrameworkCodeSwitcher>
  <div slot="astro">
```astro
---
import { Button } from "@/components/starwind/button";
import { Kbd, KbdGroup } from "@/components/starwind/kbd";
---

<Button variant="outline" size="sm" class="pr-2">
  Accept
  <Kbd>⏎</Kbd>
</Button>

<Button variant="outline" size="sm" class="pr-2">
  Cancel
  <Kbd>Esc</Kbd>
</Button>

<Button variant="outline" size="sm" class="pr-2">
  Save
  <KbdGroup>
    <Kbd>Ctrl</Kbd>
    <span>+</span>
    <Kbd>S</Kbd>
  </KbdGroup>
</Button>
```
  </div>
  <div slot="react">
```tsx
import { Button } from "@/components/starwind/button";
import { Kbd, KbdGroup } from "@/components/starwind/kbd";

export function Example() {
  return (
    <>
      <Button variant="outline" size="sm" className="pr-2">
        Accept
        <Kbd>⏎</Kbd>
      </Button>

      <Button variant="outline" size="sm" className="pr-2">
        Cancel
        <Kbd>Esc</Kbd>
      </Button>

      <Button variant="outline" size="sm" className="pr-2">
        Save
        <KbdGroup>
          <Kbd>Ctrl</Kbd>
          <span>+</span>
          <Kbd>S</Kbd>
        </KbdGroup>
      </Button>
    </>
  );
}
```
  </div>
  <div slot="vue">
```vue
<script setup lang="ts">
import { Button } from "@/components/starwind/button";
import { Kbd, KbdGroup } from "@/components/starwind/kbd";
</script>

<template>
  <Button variant="outline" size="sm" class="pr-2">
    Accept
    <Kbd>⏎</Kbd>
  </Button>

  <Button variant="outline" size="sm" class="pr-2">
    Cancel
    <Kbd>Esc</Kbd>
  </Button>

  <Button variant="outline" size="sm" class="pr-2">
    Save
    <KbdGroup>
      <Kbd>Ctrl</Kbd>
      <span>+</span>
      <Kbd>S</Kbd>
    </KbdGroup>
  </Button>
</template>
```
  </div>
</FrameworkCodeSwitcher>

## Common Shortcuts

<FrameworkCodeSwitcher>
  <div slot="astro">
```astro
---
import { Kbd, KbdGroup } from "@/components/starwind/kbd";
---

<div class="flex flex-col gap-3 min-w-sm">
  <div class="flex items-center gap-3 justify-between">
    <span class="text-sm">Copy</span>
    <KbdGroup>
      <Kbd>Ctrl</Kbd>
      <span>+</span>
      <Kbd>C</Kbd>
    </KbdGroup>
  </div>
  <div class="flex items-center gap-3 justify-between">
    <span class="text-sm">Paste</span>
    <KbdGroup>
      <Kbd>Ctrl</Kbd>
      <span>+</span>
      <Kbd>V</Kbd>
    </KbdGroup>
  </div>
  <div class="flex items-center gap-3 justify-between">
    <span class="text-sm">Cut</span>
    <KbdGroup>
      <Kbd>Ctrl</Kbd>
      <span>+</span>
      <Kbd>X</Kbd>
    </KbdGroup>
  </div>
  <div class="flex items-center gap-3 justify-between">
    <span class="text-sm">Undo</span>
    <KbdGroup>
      <Kbd>Ctrl</Kbd>
      <span>+</span>
      <Kbd>Z</Kbd>
    </KbdGroup>
  </div>
</div>
```
  </div>
  <div slot="react">
```tsx
import { Kbd, KbdGroup } from "@/components/starwind/kbd";

export function Example() {
  return (
    <>
      <div className="flex flex-col gap-3 min-w-sm">
        <div className="flex items-center gap-3 justify-between">
          <span className="text-sm">Copy</span>
          <KbdGroup>
            <Kbd>Ctrl</Kbd>
            <span>+</span>
            <Kbd>C</Kbd>
          </KbdGroup>
        </div>
        <div className="flex items-center gap-3 justify-between">
          <span className="text-sm">Paste</span>
          <KbdGroup>
            <Kbd>Ctrl</Kbd>
            <span>+</span>
            <Kbd>V</Kbd>
          </KbdGroup>
        </div>
        <div className="flex items-center gap-3 justify-between">
          <span className="text-sm">Cut</span>
          <KbdGroup>
            <Kbd>Ctrl</Kbd>
            <span>+</span>
            <Kbd>X</Kbd>
          </KbdGroup>
        </div>
        <div className="flex items-center gap-3 justify-between">
          <span className="text-sm">Undo</span>
          <KbdGroup>
            <Kbd>Ctrl</Kbd>
            <span>+</span>
            <Kbd>Z</Kbd>
          </KbdGroup>
        </div>
      </div>
    </>
  );
}
```
  </div>
  <div slot="vue">
```vue
<script setup lang="ts">
import { Kbd, KbdGroup } from "@/components/starwind/kbd";
</script>

<template>
  <div class="flex flex-col gap-3 min-w-sm">
    <div class="flex items-center gap-3 justify-between">
      <span class="text-sm">Copy</span>
      <KbdGroup>
        <Kbd>Ctrl</Kbd>
        <span>+</span>
        <Kbd>C</Kbd>
      </KbdGroup>
    </div>
    <div class="flex items-center gap-3 justify-between">
      <span class="text-sm">Paste</span>
      <KbdGroup>
        <Kbd>Ctrl</Kbd>
        <span>+</span>
        <Kbd>V</Kbd>
      </KbdGroup>
    </div>
    <div class="flex items-center gap-3 justify-between">
      <span class="text-sm">Cut</span>
      <KbdGroup>
        <Kbd>Ctrl</Kbd>
        <span>+</span>
        <Kbd>X</Kbd>
      </KbdGroup>
    </div>
    <div class="flex items-center gap-3 justify-between">
      <span class="text-sm">Undo</span>
      <KbdGroup>
        <Kbd>Ctrl</Kbd>
        <span>+</span>
        <Kbd>Z</Kbd>
      </KbdGroup>
    </div>
  </div>
</template>
```
  </div>
</FrameworkCodeSwitcher>

## Arrow Keys

<FrameworkCodeSwitcher>
  <div slot="astro">
```astro
---
import { Kbd } from "@/components/starwind/kbd";
---

<div class="flex flex-col items-center gap-2">
  <Kbd>↑</Kbd>
  <div class="flex gap-2">
    <Kbd>←</Kbd>
    <Kbd>↓</Kbd>
    <Kbd>→</Kbd>
  </div>
</div>
<p class="text-sm text-muted-foreground">Use arrow keys to navigate</p>
```
  </div>
  <div slot="react">
```tsx
import { Kbd } from "@/components/starwind/kbd";

export function Example() {
  return (
    <>
      <div className="flex flex-col items-center gap-2">
        <Kbd>↑</Kbd>
        <div className="flex gap-2">
          <Kbd>←</Kbd>
          <Kbd>↓</Kbd>
          <Kbd>→</Kbd>
        </div>
      </div>
      <p className="text-sm text-muted-foreground">Use arrow keys to navigate</p>
    </>
  );
}
```
  </div>
  <div slot="vue">
```vue
<script setup lang="ts">
import { Kbd } from "@/components/starwind/kbd";
</script>

<template>
  <div class="flex flex-col items-center gap-2">
    <Kbd>↑</Kbd>
    <div class="flex gap-2">
      <Kbd>←</Kbd>
      <Kbd>↓</Kbd>
      <Kbd>→</Kbd>
    </div>
  </div>
  <p class="text-sm text-muted-foreground">Use arrow keys to navigate</p>
</template>
```
  </div>
</FrameworkCodeSwitcher>

## API Reference
### Kbd
- Inherits kbd attributes.

### KbdGroup
- Inherits kbd attributes.

## Changelog

### v1.1.1

- Named the generated aggregate default export so React and Astro tooling can identify the installed component cleanly.

### v1.1.0

- Added contract-generated Astro and React implementations while preserving the component's existing public API and styling.

### v1.0.2

- Refactor tailwind variants functions into separate `variants.ts` file

### v1.0.0

- Initial release with starwind v1.11.0