Skip to main content

Button

StorybookView in Storybook

Explore interactive examples and all component variations in our Storybook.

The Button component is a fundamental UI element that offers multiple visual variants, sizes, and states. Built with accessibility in mind, it supports icons, loading states, and can be rendered as other elements.

Basic Usage

Variants

Sizes

With Icons

Loading State

Form Actions

Disabled States

Properties

Button

PropertyTypeDefaultDescription
variant"default" | "destructive" | "outline" | "secondary" | "ghost" | "link""default"Visual variant of the button.
size"sm" | "md" | "lg" | "xl" | "icon""md"Size of the button.
asChildbooleanfalseIf true, renders as the child element instead of a button.
isLoadingbooleanfalseIf true, shows loading spinner.
disabledbooleanfalseIf true, disables the button.
classNamestring-Additional CSS classes.

Variants

VariantDescriptionRecommended Use
defaultPrimary button with colored backgroundMain actions, CTAs
destructiveRed button for destructive actionsDelete, remove, cancel
outlineButton with border, transparent backgroundSecondary actions
secondaryButton with light gray backgroundAlternative actions
ghostTransparent button, hover onlySubtle actions, menus
linkLink appearance with underlineLinks that look like buttons

Sizes

SizeHeightRecommended Use
sm32pxCompact spaces, tables
md36pxGeneral use (default)
lg40pxForms, important CTAs
xl48pxHero sections, landing pages
icon36x36pxIcons only, no text

Features

Accessibility

  • Full keyboard support (Enter, Space)
  • Visible focus states
  • Proper ARIA attributes
  • Screen reader compatible
  • Clear disabled states
  • Adequate contrast in all variants

Loading States

  • Built-in loading spinner
  • Automatic disabled state when loading
  • Smooth transitions

Flexibility

  • Can render as any element with asChild
  • Icon support with proper spacing
  • Customizable with Tailwind CSS

Common Use Cases

The Button component is perfect for:

  • Primary actions - Save, submit, create, confirm
  • Secondary actions - Cancel, edit, view details
  • Destructive actions - Delete, remove, reset
  • Navigation - Links that need button styling
  • Form controls - Submit, reset, add item
  • Call-to-actions - Sign up, get started, learn more
  • Icon actions - Close, expand, settings

Best Practices

  1. Use appropriate variants - default for primary actions, destructive for dangerous actions
  2. Maintain consistency - Use same sizes in similar contexts
  3. Provide feedback - Use isLoading for async operations
  4. Be descriptive - Use clear text that describes the action
  5. Consider hierarchy - Primary buttons should stand out visually
  6. Test accessibility - Verify keyboard navigation and screen readers
  7. Use icons thoughtfully - Icons should complement, not replace clear text