# Button

- **[Atoms](/components/)**

Triggers an action. Five variants, three sizes, a 44 pixel hit area at every size.

## When to use

- **Use for**: Saving, sending, confirming a step. One primary button per view.
- **Not for**: Going to another page. Use Button link or Text link.
- **Pairs with**: Field, Card, Copy button.

## Preview

button.tsx

```
import { Theme } from '@/components/klarhimmel/theme/style';
import { Button } from '@/components/klarhimmel/ui/button';

export default function Example() {
  return (
    <Theme theme="brand">
      <div className="flex gap-3">
        <Button>Save changes</Button>
        <Button variant="secondary">Cancel</Button>
      </div>
    </Theme>
  );
}
```

## Import

- **CLI**

  ```
  npx shadcn add @klarhimmel/button
  ```
- **Import**

  ```
  import { Button } from '@/components/klarhimmel/ui/button';
  ```

- **Files**: button.tsx, in components/klarhimmel/ui/. With it: editing, theme, utils. npm: radix-ui.
- **Render in**: Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

## Examples

- **Sizes**

  ```
  import { Button } from '@/components/klarhimmel/ui/button';
  
  export default function ButtonSizes() {
    return (
      <div className="flex flex-wrap items-center gap-3">
        <Button size="sm">Small</Button>
        <Button size="md">Medium</Button>
        <Button size="lg">Large</Button>
      </div>
    );
  }
  ```
- **States**

  ```
  import { Button } from '@/components/klarhimmel/ui/button';
  
  export default function ButtonStates() {
    return (
      <div className="flex flex-wrap items-center gap-3">
        <Button>Default</Button>
        <Button variant="secondary">Default</Button>
        <Button disabled>Disabled</Button>
        <Button variant="secondary" disabled>Disabled</Button>
      </div>
    );
  }
  ```
- **With icon**

  ```
  import { ArrowRight, Download, Plus } from 'lucide-react';
  import { Button } from '@/components/klarhimmel/ui/button';
  
  export default function ButtonWithIcon() {
    return (
      <div className="flex flex-wrap items-center gap-3">
        <Button icon={<Plus aria-hidden className="size-4" />}>New project</Button>
        <Button variant="secondary" icon={<Download aria-hidden className="size-4" />}>Download</Button>
        <Button variant="ghost" iconEnd={<ArrowRight aria-hidden className="size-4" />}>Continue</Button>
      </div>
    );
  }
  ```
- **As child**

  ```
  import { Button } from '@/components/klarhimmel/ui/button';
  
  /** Composition: Button styles the child it wraps, here a link, so navigation stays a real <a>. */
  export default function ButtonAsChild() {
    return (
      <div className="flex flex-wrap items-center gap-3">
        <Button asChild>
          <a href="#docs">Read the docs</a>
        </Button>
        <Button asChild variant="secondary">
          <a href="#changelog">View changelog</a>
        </Button>
      </div>
    );
  }
  ```

## Props

- **variant**: Visual style. Primary is ink on canvas; danger is a quiet outline for ending or removing something.
- **size**: Height and padding. The hit area stays 44 px.
- **icon**: Icon before the label.
- **iconEnd**: Icon after the label.
- **full**: Stretch to the container width.
- **asChild**: Render the single child (an <a>, a router Link) with button styling instead of a <button>.
- **native attributes**: Every native attribute of the element passes through, className included.

## Accessibility

- Enter / Space · Activates the button
- Tab · Moves focus; the ring is always visible

[Accessibility](/get-started/accessibility)

An icon-only button needs an aria-label.

[Previous](/components/score-ring)

[Next](/components/text-link)
