# Button

> Shadcn compatible React button on Base UI with eight variants, nine sizes including icon sizes, a pressed state and render prop support for links.

- Kind: Component (Buttons)
- Docs: https://ui.minidev.pro/docs/button
- Source (registry JSON with the full file): https://ui.minidev.pro/r/button.json
- License: MIT. One file, yours to edit after install.

## When to use

Use `default` (ink) for the primary action, `outline` for secondary, `ghost` in toolbars, `destructive` for irreversible actions, `accent` at most once per screen, `link` for inline text actions. For an icon-only button use [`IconButton`](https://ui.minidev.pro/docs/icon-button) (it requires `aria-label`). To render a link that looks like a button, pass `render={<a href="/pricing" />}` (or a Next.js `<Link />`); `nativeButton` is set for you. Disable with `disabled`; Base UI keeps it focusable when you also pass `focusableWhenDisabled`.

Solid variants carry an inner top highlight and bottom edge (shadow-ink), outline a 1px key edge (shadow-key). Hover changes one property, press sinks 0.5px, nothing shifts layout.

Sizes: xs 28px, sm 32px, default 36px, lg 44px, xl 48px; icon, icon-xs, icon-sm, icon-lg are square.

## Installation

### shadcn CLI (copies the source into your project)

```bash
npx shadcn@latest add @minidev/button
```

Writes `components/ui/button.tsx` and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/button.json`.

### npm package

```bash
npm i minidev-ui-kit @base-ui/react class-variance-authority
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

```tsx
import { Button, buttonVariants } from "@/components/ui/button"
```

From the npm package:

```tsx
import { Button } from "minidev-ui-kit/ui/button"
```

## Usage

```tsx
import { Button } from "@/components/ui/button"

export function Example() {
  return (
    <Button className="w-full">Continue</Button>
  )
}
```

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `variant` | `"default" \| "accent" \| "outline" \| "secondary" \| "ghost" \| "soft" \| "destructive" \| "link"` | `"default"` | no |  |
| `size` | `"xs" \| "sm" \| "default" \| "lg" \| "xl" \| "icon" \| "icon-xs" \| "icon-sm" \| "icon-lg"` | `"default"` | no |  |

Also accepts every prop of `ButtonPrimitive props`, passed through to the root element.

## Examples

### Variants

default (ink) is the primary action, outline is secondary, ghost sits in toolbars, destructive is for what cannot be undone, and accent appears at most once per screen.

```tsx
<Button>Save invoice</Button>
<Button variant="accent">Upgrade to Pro</Button>
<Button variant="outline">Preview</Button>
<Button variant="secondary">Duplicate</Button>
<Button variant="soft">Add note</Button>
<Button variant="ghost">Skip</Button>
<Button variant="destructive">Void invoice</Button>
<Button variant="link">View history</Button>
```

### Sizes

xs 28px, sm 32px, default 36px, lg 44px and xl 48px; icons scale with the size, so never size them by hand.

```tsx
<Button size="xs">Export</Button>
<Button size="sm">Export</Button>
<Button>Export</Button>
<Button size="lg">Export</Button>
<Button size="xl">Export</Button>
```

### With icons

Icons inherit the size; put the arrow after the label for forward actions. For an icon with no label, use IconButton, which requires aria-label.

```tsx
<Button><PlusIcon /> New invoice</Button>
<Button variant="outline" size="sm"><DownloadIcon /> Export CSV</Button>
<Button variant="outline">Continue <ArrowRightIcon /></Button>
```

### Loading state

Disable the button while the request runs and swap the icon for a Spinner; the label says what is happening, not just that something is.

```tsx
function SendInvoice() {
  const [state, setState] = React.useState<"idle" | "sending" | "sent">("idle")
  const send = () => {
    setState("sending")
    setTimeout(() => setState("sent"), 1200)
  }
  return (
    <div className="flex flex-col items-center gap-3">
      <Button onClick={send} disabled={state === "sending"} aria-busy={state === "sending"}>
        {state === "sending" ? <Spinner size="sm" label="Sending" /> : <SendIcon />}
        {state === "sending" ? "Sending…" : state === "sent" ? "Send again" : "Send INV-2041"}
      </Button>
      <p className="text-xs text-fg-muted" aria-live="polite">
        {state === "sent" ? "Sent to billing@northwind.example." : "Disabled while the request is in flight, so it cannot send twice."}
      </p>
    </div>
  )
}
```

### As a link

render swaps the element, so navigation stays a real link (pass a Next.js <Link /> the same way); nativeButton is set for you.

```tsx
<Button render={<a href="#pricing" />} variant="accent" size="lg">
  See pricing <ArrowRightIcon />
</Button>
<Button render={<a href="#docs" />} variant="outline" size="lg">
  Read the docs
</Button>
```

### Disabled

disabled removes it from the tab order; add focusableWhenDisabled when a tooltip or screen reader still needs to reach it and explain why.

```tsx
<Button disabled>Approve</Button>
<Button variant="outline" disabled focusableWhenDisabled aria-describedby="approve-why">
  Approve
</Button>
<p id="approve-why" className="text-xs text-fg-muted">Only Maya Chen can approve bills over $10,000.</p>
```

## Keyboard interactions

| Key | Action |
| --- | --- |
| `Enter` or `Space` | Activates the button. With `render={<a />}`, Enter follows the link and Space activates it too. |
| `Tab` | Moves focus to the button. A disabled button is skipped unless `focusableWhenDisabled` is set. |

## Accessibility

- Renders a native `<button>` by default. With `render`, `nativeButton` becomes `false` and Base UI adds the Enter and Space handling. A `render` element with `href` keeps its link role; any other element gets `role="button"`.
- On a native button, `disabled` sets the `disabled` attribute. With `focusableWhenDisabled` it sets `aria-disabled="true"` instead, so the button stays in the Tab order and screen readers still find it.
- The focus ring is `focus-visible` only: a 2px accent ring with a 2px offset, so it shows for keyboard users and not on mouse clicks.
- An icon-only button needs an accessible name. Use [`IconButton`](https://ui.minidev.pro/docs/icon-button), which requires `aria-label`.

## FAQ

### Why doesn't my Button submit the form?

Base UI renders the `<button>` with `type="button"`, so pressing it inside a `<form>` does nothing by default. Pass `type="submit"` on the button that should submit.

### How do I make a Next.js Link look like a button?

Pass the link as `render`: `<Button render={<Link href="/pricing" />}>See pricing</Button>`. `nativeButton` is set to `false` for you, and the element keeps its link role, so screen readers announce a link. You can also put `buttonVariants({ variant: "outline" })` in the `className` of a plain `<Link>`.

### How do I show a loading state?

There is no `loading` prop. Set `disabled` while the request runs and put a [`Spinner`](https://ui.minidev.pro/docs/spinner) before the label: `<Button disabled={saving} focusableWhenDisabled><Spinner size="sm" label="Saving" /> Save</Button>`. `focusableWhenDisabled` keeps keyboard focus on the button while it is disabled.

### Can I use Button in a Next.js Server Component?

Yes, for static buttons and `render` links. The file is marked `"use client"`, and a Server Component cannot pass functions to it, so a button with `onClick` belongs in a client component. A Server Action is the exception: pass it as `formAction`.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- npm: `@base-ui/react`, `class-variance-authority`

## Related

- [Icon Button](https://ui.minidev.pro/docs/icon-button/md): A square React button for icon only actions in small, default and large sizes with every Button variant. Its aria-label prop is required, so it is always named.
- [Link](https://ui.minidev.pro/docs/link/md): A styled anchor with the accent color, underline on hover and a visible focus ring. Accepts every native anchor prop, so it works with Next.js or plain hrefs.
- [Auth Card](https://ui.minidev.pro/docs/auth-card/md): Centered Tailwind sign in card with a title, optional description, a slot for fields and providers, and a divided footer for sign up or reset links.
- [Button Group](https://ui.minidev.pro/docs/button-group/md): Groups adjacent buttons into one segmented control in Tailwind, joining borders and rounding only the outer corners. Uses role group for toolbars.
- [Copy Button](https://ui.minidev.pro/docs/copy-button/md): React copy to clipboard button that writes a value, then swaps to a check icon and Copied label for a moment. Accepts every Button variant and size.
- [Email Button](https://ui.minidev.pro/docs/email-button/md): Solid link button for email templates with a fixed height, padding and rounded corners. Uses an anchor so it survives email clients that strip buttons.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
