Join our Discord Community

Button

React button component with multiple variants, sizes, and states. Perfect for forms, navigation, and user actions with full accessibility support.

Need users to take action? Buttons are the foundation of every interface - from simple clicks to complex form submissions. The Button component handles everything from primary calls-to-action to subtle icon buttons.

Loading component...

Built with Radix UI Slot for maximum flexibility and class-variance-authority for type-safe styling.

npx shadcn@latest add button

Why buttons work everywhere

Users expect buttons to behave consistently across every app and website:

  • Visual hierarchy - Primary, secondary, and destructive actions are instantly recognizable
  • Touch and click targets - Properly sized for both mouse and finger interaction
  • Keyboard navigation - Tab, Enter, and Space work exactly as expected
  • Loading states - Clear feedback during async operations
  • Accessibility first - Screen readers announce button purpose and state
  • Flexible composition - Work as links, form submits, or custom components
  • Consistent spacing - Icons and text align perfectly

Common button patterns you'll build

All visual variants

Six different styles for every use case:

Loading component...

Secondary actions

Subtle styling for less important actions:

Loading component...

Destructive actions

Clear warning for delete, remove, or cancel operations:

Loading component...

Outline style

Bordered buttons that work great on colored backgrounds:

Loading component...

Ghost buttons

Minimal styling that appears on hover and focus:

Loading component...

Button functionality with link styling:

Loading component...

Different sizes

From compact to prominent sizing:

Loading component...

Icon-only buttons

Compact buttons for toolbars and tight spaces:

Loading component...

Text with icons

Combining text and visual indicators:

Loading component...

Loading states

Feedback during async operations:

Loading component...

API Reference

Button

The main button component built on Radix UI Slot with comprehensive variant and size options.

PropTypeDefaultDescription
variant"default" | "destructive" | "outline" | "secondary" | "ghost" | "link""default"Visual style variant for different use cases
size"default" | "sm" | "lg" | "icon""default"Size of the button for different contexts
asChildbooleanfalseRender as a child component (e.g., Next.js Link) using Radix UI Slot
disabledbooleanfalseDisables the button and applies disabled styling
type"button" | "submit" | "reset""button"HTML button type for form integration
onClick(event: MouseEvent) => void-Click event handler
classNamestring-Additional CSS classes for custom styling
childrenReact.ReactNode-Button content including text, icons, and other elements

Button Variants

VariantUse CaseAppearance
"default"Primary actions, main CTAsSolid background with primary color
"secondary"Secondary actions, alternative optionsMuted solid background
"destructive"Delete, remove, dangerous actionsRed background with warning styling
"outline"Secondary actions on colored backgroundsTransparent with border
"ghost"Subtle actions, hover reveals backgroundTransparent, minimal styling
"link"Navigation that should look like linksUnderlined text styling

Button Sizes

SizeUse CaseDimensions
"sm"Compact spaces, secondary actionsHeight: 32px, smaller padding
"default"Standard use casesHeight: 40px, balanced padding
"lg"Prominent actions, hero sectionsHeight: 44px, larger padding
"icon"Icon-only buttons40x40px square for single icons

States and Styling

The button automatically handles various states:

StateDescriptionStyling
hoverMouse hover interactionDarker background, smooth transition
focus-visibleKeyboard focusRing outline for accessibility
activeClick/press stateSlightly pressed appearance
disabledNon-interactive stateReduced opacity, no pointer events
aria-invalidForm validation errorRed border and ring

Button best practices

What makes buttons feel intuitive and accessible:

  • Clear action words - "Save", "Delete", "Submit" instead of "OK" or "Click here"
  • Consistent sizing - Use the same size for buttons at the same importance level
  • Visual hierarchy - Primary, secondary, ghost, and destructive variants guide users
  • Touch targets - Minimum 44px height for mobile accessibility
  • Loading feedback - Show progress during async operations
  • Keyboard support - Tab, Enter, and Space work perfectly
  • Icon alignment - Icons and text line up naturally with proper spacing
  • Disabled states - Clear visual feedback when actions aren't available