---
title: Button
description: A clickable button component with multiple variants and states
links:
  rac: Button
  source: button/button.tsx
  styles: button.css
  storybook: Components/Buttons/Button
  figma: true
---

## Usage

```tsx
import { Button } from '@heroui/react';
```

<ComponentPreview
  name="button-basic"
/>

## Examples

### Variants

<ComponentPreview
  name="button-variants"
/>

### Sizes

<ComponentPreview
  name="button-sizes"
/>

### With Icons

<ComponentPreview
  name="button-with-icons"
/>

### Icon Only

<ComponentPreview
  name="button-icon-only"
/>

### Loading

<ComponentPreview
  name="button-loading"
/>

### Loading State

<ComponentPreview
  name="button-loading-state"
/>

### Full Width

<ComponentPreview
  name="button-full-width"
/>

### Disabled State

<ComponentPreview
  name="button-disabled"
/>

### Social Buttons

<ComponentPreview
  name="button-social"
/>

### Render Function

<ComponentPreview
  name="button-render-function"
/>

### Adding custom variants

You can extend HeroUI components by wrapping them and adding your own custom variants.

<ComponentPreview
  name="button-custom-variants"
/>

### Adding Ripple Effect

The Button component supports ripple effects through composition, allowing you to nest ripple components as children. This example uses [m3-ripple](https://github.com/saltyaom/m3-ripple).

<ComponentPreview
  name="button-ripple-effect"
/>

## Customization

### Tailwind CSS

<ComponentPreview name="button-custom-styles" />

### Global CSS

To customize the Button component classes, you can use the `@layer components` directive.
[Learn more](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes).

```css
@layer components {
  .button {
    @apply bg-purple-500 text-white hover:bg-purple-600;
  }

  .button--icon-only {
    @apply rounded-lg bg-blue-500;
  }
}
```

## Styling Reference

HeroUI follows the [BEM](https://getbem.com/) methodology to ensure component variants and states are reusable and easy to customize.

### CSS Classes

The Button component uses these CSS classes ([View source styles](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/button.css)):

#### Base & Size Classes [!toc]
- `.button` - Base button styles
- `.button--sm` - Small size variant
- `.button--md` - Medium size variant
- `.button--lg` - Large size variant

#### Variant Classes [!toc]
- `.button--primary`
- `.button--secondary`
- `.button--tertiary`
- `.button--outline`
- `.button--ghost`
- `.button--danger`

#### Modifier Classes [!toc]
- `.button--icon-only`
- `.button--icon-only.button--sm`
- `.button--icon-only.button--lg`

### Interactive States

The button supports both CSS pseudo-classes and data attributes for flexibility:

- **Hover**: `:hover` or `[data-hovered="true"]`
- **Active/Pressed**: `:active` or `[data-pressed="true"]` (includes scale transform)
- **Focus**: `:focus-visible` or `[data-focus-visible="true"]` (shows focus ring)
- **Disabled**: `:disabled` or `[aria-disabled="true"]` (reduced opacity, no pointer events)
- **Pending**: `[data-pending]` (no pointer events during loading)

## API Reference

### Button

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `variant` | `'primary' \| 'secondary' \| 'tertiary' \| 'outline' \| 'ghost' \| 'danger'` | `'primary'` | Visual style variant |
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Size of the button |
| `fullWidth` | `boolean` | `false` | Whether the button should take full width of its container |
| `isDisabled` | `boolean` | `false` | Whether the button is disabled |
| `isPending` | `boolean` | `false` | Whether the button is in a loading state |
| `isIconOnly` | `boolean` | `false` | Whether the button contains only an icon |
| `onPress` | `(e: PressEvent) => void` | - | Handler called when the button is pressed |
| `children` | `React.ReactNode \| (values: ButtonRenderProps) => React.ReactNode` | - | Button content or render prop |
| `render` | `DOMRenderFunction<keyof React.JSX.IntrinsicElements, ButtonRenderProps>` | - | Overrides the default DOM element with a custom render function.|

### Render Props

When using the render prop pattern, these values are provided:

| Prop | Type | Description |
|------|------|-------------|
| `isPending` | `boolean` | Whether the button is in a loading state |
| `isPressed` | `boolean` | Whether the button is currently pressed |
| `isHovered` | `boolean` | Whether the button is hovered |
| `isFocused` | `boolean` | Whether the button is focused |
| `isFocusVisible` | `boolean` | Whether the button should show focus indicator |
| `isDisabled` | `boolean` | Whether the button is disabled |

## Related Showcases

<RelatedShowcases component="Button" />

## Related Components

<RelatedComponents component="button" />
