All components

Button

Buttons

A polymorphic button with five variants and four sizes, built on Radix Slot so it can render as any element via `asChild`.

Overview

A foundational button built on class-variance-authority for type-safe variants and Radix Slot for polymorphism. It is the building block most other components compose with.

When to use

Use the primary variant for the single most important action in a view, and secondary / outline / ghost for everything supporting. Reserve link for inline, low-emphasis actions.

Polymorphism

Because the button is built on Radix Slot, the asChild prop lets it render as any element while keeping its styling — most often a Next.js Link:

<Button asChild><Link href="/x">Go</Link></Button>

This keeps a single source of truth for button styling instead of duplicating classes onto anchors.

Accessibility

Renders a native <button> by default, so keyboard activation and focus come for free. A visible focus-visible ring is included. When using asChild, make sure the child is an interactive element (a link or button).

Installation

Terminal
npx shadcn@latest add https://ui.saumyarex.xyz/r/button.json

Props

PropTypeDefaultDescription
variant"primary" | "secondary" | "ghost" | "outline" | "link""primary"Visual style of the button.
size"sm" | "md" | "lg" | "icon""md"Control the height and padding.
asChildbooleanfalseMerge props onto the child element (e.g. a Next <Link>) instead of rendering a <button>.
...propsReact.ComponentProps<"button">All native button attributes are forwarded.

Dependencies

@radix-ui/react-slotclass-variance-authorityclsxtailwind-merge