Button
A native button with ten styles to choose from, icon sizes and a loading state, plus copyable recipes for more.
Use Button for actions: submitting a form, opening a dialog, confirming a choice. For navigation use a link instead, because a link is announced and behaves differently.
Installation
pnpm dlx shadcn@latest add https://components.abdulqadirmsingi.com/r/button.json
Usage
import { Button } from "@/components/ui/button";
export function Example() {
return <Button variant="outline">Continue</Button>;
}Variants
Pick the one that fits the job:
| Variant | Use it for |
|---|---|
default | The main action on a page. Black in light mode, white in dark. |
accent | A brand-coloured main action, in saffron. |
outline | A secondary action next to a main one. |
soft | A quiet filled button when an outline feels too light. |
ghost | Toolbars and dense rows, where a border would add noise. |
link | A low-emphasis action that reads like a link but still acts like a button. |
destructive | Deleting or removing, shown in the danger colour. |
brutal | A bold, flat style: a hard shadow that the button presses into. |
wipe | A fill that sweeps in from the start edge on hover. |
glass | Over images or colour. It blurs what is behind it, so it needs a colourful backdrop. |
Alternatives
You are not limited to the built-in styles. These are built by passing className to the same Button, so each one is a few classes you can paste and change. Nothing extra is installed.
Arrow slide. The arrow nudges forward on hover and flips for right-to-left languages.
<Button variant="accent" shape="pill" size="lg" className="group">
Get started
<svg
aria-hidden="true"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="transition-transform duration-[var(--duration-base)] group-hover:translate-x-1 motion-reduce:group-hover:translate-x-0 rtl:-scale-x-100 rtl:group-hover:-translate-x-1"
>
<path d="M3 8h10M9 4l4 4-4 4" />
</svg>
</Button>Glow. A soft saffron ring that widens on hover.
<Button
variant="accent"
shape="pill"
className="shadow-[0_0_0_4px_color-mix(in_oklab,var(--accent)_35%,transparent)] hover:shadow-[0_0_0_8px_color-mix(in_oklab,var(--accent)_35%,transparent)]"
>
Glow
</Button>Status dot. A dot that pulses only for people who have not asked for reduced motion. The dot is decorative, so the words carry the meaning.
<Button variant="outline" shape="pill">
<span aria-hidden="true" className="size-2 rounded-full bg-success motion-safe:animate-pulse" />
Live now
</Button>Count. A small number beside the label. Put the number in the text too, so it is read out.
<Button variant="soft" shape="pill">
Messages
<span className="rounded-full bg-foreground px-2 text-xs text-background">3</span>
</Button>Sizes
For a square icon-only button use size="icon-sm", "icon" or "icon-lg" (32, 40 and 48 pixels) and give it an aria-label.
Icons and shape
Put an inline SVG before or after the text. Icons are sized to 16 pixels automatically and are not clickable on their own. shape="pill" makes the ends fully round.
Loading
loading shows a spinner and disables the button, so a second click can't submit a payment twice.
Also show a status message somewhere on the page. aria-busy on its own is not announced by every screen reader.
States
Props
Button extends all native <button> props and spreads them onto the element, including ref (React 19).
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "accent" | "outline" | "soft" | "ghost" | "link" | "destructive" | "brutal" | "wipe" | "glass" | "default" | Visual style; see the table above. Destructive is danger-coloured text on a light surface. |
| size | "sm" | "md" | "lg" | "icon-sm" | "icon" | "icon-lg" | "md" | Heights of 32, 40 and 48 pixels. The icon sizes are square and need an aria-label. |
| shape | "default" | "pill" | "default" | Pill makes the ends fully round. |
| loading | boolean | false | Shows a spinner, sets aria-busy and disables the button. |
| type | "button" | "submit" | "reset" | "button" | Defaults to button so it never submits a form by accident. |
| className | string | – | Merged with the built-in classes; yours win on conflicts. |
Accessibility
- It renders a native
<button>, so Enter and Space activate it and screen readers announce it as a button. - A visible focus ring appears on keyboard focus only (
:focus-visible). - Disabled buttons are removed from pointer interaction and dimmed.
- Under
prefers-reduced-motion, the press animation and transitions are turned off, and the loading spinner pulses instead of rotating. - Icon-only buttons have no visible text, so they must have an
aria-label. linkis still a<button>: use a real link for navigation.wipealso flips its label colour on keyboard focus, not only on hover.brutalandwipekeep their shape and colours under reduced motion; only the movement and the sweep are removed.- The smallest size is 32 pixels high, above the 24-pixel WCAG 2.2 minimum but below the 44-pixel touch target we prefer. Use
lgfor primary touch actions.
Tokens used
--primary, --primary-foreground, --accent, --accent-foreground, --accent-ink, --background, --foreground, --border, --muted, --danger, --ring, --duration-base, --ease-out, and the glass variables.
Known limitations
- Loading disables the button, so it leaves the tab order while it waits.
- Nothing checks that an icon-only button has an aria-label; that is up to you.
- Glass text contrast has not been measured against worst-case backdrops.
Source
import { cva, type VariantProps } from "class-variance-authority";import type { ComponentProps } from "react";import { cn } from "@/lib/utils";const buttonVariants = cva( "inline-flex cursor-pointer items-center justify-center gap-2 whitespace-nowrap font-medium [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 transition-[background-color,color,box-shadow,transform,translate,scale,rotate,opacity] duration-[var(--duration-base)] ease-[var(--ease-out)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring active:scale-[0.98] disabled:pointer-events-none disabled:opacity-50 motion-reduce:transition-none motion-reduce:active:scale-100", { variants: { variant: { default: "bg-primary text-primary-foreground hover:opacity-90", outline: "border border-border bg-background text-foreground hover:bg-muted", ghost: "text-foreground hover:bg-muted", glass: "zuri-glass text-foreground hover:opacity-90", destructive: "border border-border bg-background text-danger hover:bg-muted", // The saffron brand fill. --accent-foreground is dark in both themes, which keeps contrast. accent: "bg-accent text-accent-foreground hover:opacity-90", // A quiet filled button for secondary actions that still need a visible shape. soft: "bg-muted text-foreground hover:bg-border", // Looks like a link but is still a button, for low-emphasis actions. link: "text-accent-ink underline underline-offset-4 hover:no-underline", // A hard offset shadow that the button presses into. brutal: "border border-foreground bg-background text-foreground shadow-[3px_3px_0_0_var(--foreground)] hover:-translate-x-px hover:-translate-y-px hover:shadow-[4px_4px_0_0_var(--foreground)] active:translate-x-[3px] active:translate-y-[3px] active:shadow-none motion-reduce:hover:translate-x-0 motion-reduce:hover:translate-y-0", // A solid fill wipes in from the start edge on hover, and the label flips to match. wipe: "relative isolate overflow-hidden border border-foreground bg-background text-foreground before:absolute before:inset-0 before:-z-10 before:origin-left before:scale-x-0 before:bg-foreground before:transition-transform before:duration-[var(--duration-slow)] before:ease-[var(--ease-out)] hover:text-background hover:before:scale-x-100 focus-visible:text-background focus-visible:before:scale-x-100 motion-reduce:before:transition-none rtl:before:origin-right", }, size: { sm: "min-h-8 rounded-md px-3 text-sm", md: "min-h-10 rounded-md px-4 text-sm", lg: "min-h-12 rounded-lg px-6 text-base", // Icon-only buttons are square and need an aria-label. "icon-sm": "size-8 rounded-md p-0", icon: "size-10 rounded-md p-0", "icon-lg": "size-12 rounded-lg p-0", }, // Listed after size so tailwind-merge lets the pill radius win. shape: { default: "", pill: "rounded-full" }, }, defaultVariants: { variant: "default", size: "md", shape: "default" }, },);export interface ButtonProps extends ComponentProps<"button">, VariantProps<typeof buttonVariants> { /** * Shows a spinner and disables the button, which also blocks a double submit. * Pair it with a status message: `aria-busy` alone is not announced everywhere. */ loading?: boolean;}/** * A native `<button>`; pass `type="submit"` explicitly when inside a form. * Icon-only sizes (`icon-sm`, `icon`, `icon-lg`) must be given an `aria-label`. */export function Button({ className, variant, size, shape, loading = false, disabled, type = "button", children, ...props}: ButtonProps) { return ( <button type={type} disabled={disabled || loading} aria-busy={loading || undefined} className={cn(buttonVariants({ variant, size, shape }), className)} {...props} > {loading ? ( <svg aria-hidden="true" viewBox="0 0 24 24" fill="none" className="animate-spin motion-reduce:animate-pulse" > <circle cx="12" cy="12" r="9" stroke="currentColor" strokeWidth="3" opacity="0.25" /> <path d="M21 12a9 9 0 0 0-9-9" stroke="currentColor" strokeWidth="3" strokeLinecap="round" /> </svg> ) : null} {children} </button> );}export { buttonVariants };Components
Interface parts such as buttons, inputs, menus and dialogs. For heroes, headers, footers and other page sections, see [Blocks](/docs/blocks).
Copy button
A button that copies text and confirms it visually and to screen readers, in any Button style, with recipes for command boxes and share links.