Unkey
ComponentsButtons

Button

A versatile button component with multiple variants, states, and sizes

Button

A versatile button component that supports various styles, states, and interactive features. Button is built with accessibility in mind and provides consistent interaction patterns across all variants.

Each button can be customized with different variants, colors, and sizes, making it adaptable to any UI context. All buttons include proper focus states, loading indicators, and keyboard interactions.

Basic Variants

Button comes in three basic variants that serve different UI purposes:

Primary

The default button style with a solid background. Use for primary actions and main call-to-actions.

Light

Dark

Outline

Button with transparent background and visible border. Ideal for secondary actions that don't require as much visual emphasis.

Light

Dark

Ghost

Button with no background or border until interacted with. Perfect for tertiary actions or when space is limited.

Light

Dark

Color Variants

Each button variant can be combined with different color schemes to convey the nature of the action:

Danger - Primary

Solid background danger variant for destructive actions that should be clearly highlighted.

Light

Dark

Danger - Outline

Danger variant with outline style. Use for destructive actions that require less visual prominence.

Light

Dark

Danger - Ghost

Minimal danger variant. Suitable for destructive actions in tight UI spaces or alongside other content.

Light

Dark

Warning - Primary

Warning variant with solid background for actions that require caution but aren't destructive.

Light

Dark

Warning - Outline

Warning variant with outline style for secondary cautionary actions.

Light

Dark

Warning - Ghost

Warning variant with ghost style for tertiary cautionary actions.

Light

Dark

Success - Primary

Success variant with solid background for positive or confirming actions.

Light

Dark

Success - Outline

Success variant with outline style for secondary positive actions.

Light

Dark

Success - Ghost

Success variant with ghost style for subtle positive actions.

Light

Dark

Info - Primary

Info variant with solid background for positive or confirming actions.

Light

Dark

Info - Outline

Info variant with outline style for secondary positive actions.

Light

Dark

Info - Ghost

Info variant with ghost style for subtle positive actions.

Light

Dark

Size Variants

All button variants and color schemes can be combined with different sizes to fit various UI contexts.

Light

Dark

Special Features

Button includes additional features that enhance usability and interaction:

With Icons

Buttons can include icons from the Lucide library for enhanced visual meaning. Icons can be placed before or after text.

Light

Dark

With Keyboard Shortcuts

Buttons can display and respond to keyboard shortcuts for improved accessibility and power-user workflows.

Additional Features

The Button component includes some additional features not shown in the examples above:

Legacy Variant Support

For backward compatibility, the component supports legacy variants:

  • default will be mapped to primary variant
  • destructive will be mapped to primary variant with danger color

Shape Variants

For special layouts, buttons can use the shape prop:

Light

Dark

Props

The Button component accepts all standard HTML button attributes plus the following:

PropTypeDefault
variant
"default" | "destructive" | "primary" | "outline" | "ghost"
-
shape
"square"
-
color
"default" | "success" | "warning" | "danger" | "info"
-
size
"icon" | "sm" | "md" | "lg" | "xlg" | "2xlg"
-
loading
boolean
-
disabled
boolean
-
keyboard
{ display: string; trigger: (e: KeyboardEvent) => boolean; callback: (e: KeyboardEvent) => void | Promise<void>; }
-
asChild
boolean
-
loadingLabel
string
-

Usage Guidelines

When using the Button component:

  • Hierarchy: Maintain a clear visual hierarchy with your button choices
    • Use primary buttons for main actions and primary call-to-actions
    • Use outline buttons for secondary actions
    • Use ghost buttons for tertiary actions or in dense UIs
  • Color semantics: Apply color variants based on the action's impact:
    • Default for neutral or standard actions
    • Success for positive, confirming, or creative actions
    • Warning for cautionary actions that require attention
    • Danger for destructive or irreversible actions
  • Interaction states:
    • Ensure loading state is shown during asynchronous operations to prevent multiple submissions
    • Use disabled state appropriately for actions that are currently unavailable
    • Test that focus states are clearly visible for keyboard navigation
  • Sizing and spacing:
    • Use appropriate size based on the button's importance and the available space
    • Maintain consistent spacing between buttons in a group (recommend 16px/1rem)
    • For button groups, maintain consistent sizing within the group
  • Content guidelines:
    • Use concise, action-oriented text (e.g., "Save changes" instead of "Submit")
    • Add icons to enhance meaning, but avoid overloading buttons with too many elements
    • For destructive actions, consider using explicit verbs ("Delete" instead of "Remove")
  • Accessibility:
    • Consider adding keyboard shortcuts for frequently used actions
    • Ensure sufficient color contrast between text and background (WCAG AA minimum)
    • Add appropriate aria attributes for complex button behaviors
  • Responsive behavior:
    • On mobile, ensure buttons are at least 44×44px (touch target size)
    • Consider stacking buttons vertically on very small screens