elementsbutton
Button
Button component with polymorphic rendering and automatic loading state.
Import#
Slot Structure#
Trigger element with optional leading and trailing icon slots.
Examples#
Variants#
Visual variants for primary, secondary, subtle, and destructive actions.
Sizes#
Text button sizes with a leading icon to preview label and icon spacing.
Loading States#
Controlled loading and async auto-loading from click handlers.
Loading Placement#
When loading, the icon replaces leading first. If no leading is set, it replaces trailing.
Icon Buttons#
Icon-only sizes using decrease and increase actions. Always provide an accessible label when a button has no visible text.
Polymorphic#
Anchor rendering support via the polymorphic as prop.
API Reference#
Attributes#
Slot
root0 attributesInteractive button element, or the polymorphic element provided through `as`.
No attribute metadata for this slot.
Props#
| Prop | Type | Default | Description |
|---|---|---|---|
| as | "button" | undefined | button | Element or component to render as. |
| children | ComponentOrElement<{ loading: boolean; }> | undefined | — | Children of the button. Supports render function form. |
| class | ClassValue | — | Class applied to the component root or trigger element. |
| classes | ButtonT.Classes | undefined | — | — |
| disabled | boolean | undefined | — | Disabled state, including for non-button polymorphic roots. |
| leading | IconT.Name | — | Leading visual content, usually an icon. |
| loading | boolean | undefined | false | Controlled loading state. |
| loadingAuto | boolean | undefined | false | Auto toggles loading while async click handlers are pending. |
| loadingIcon | IconT.Name | icon-loading | Optional icon shown when `loading` is active. |
| onClick | JSX.EventHandlerUnion<ElementFor<"button">, MouseEvent> | undefined | — | — |
| onContextMenu | JSX.EventHandlerUnion<ElementFor<"button">, MouseEvent> | undefined | — | — |
| onKeyDown | JSX.EventHandlerUnion<ElementFor<"button">, KeyboardEvent> | undefined | — | — |
| onPointerCancel | JSX.EventHandlerUnion<ElementFor<"button">, PointerEvent> | undefined | — | — |
| onPointerDown | JSX.EventHandlerUnion<ElementFor<"button">, PointerEvent> | undefined | — | — |
| onPointerLeave | JSX.EventHandlerUnion<ElementFor<"button">, PointerEvent> | undefined | — | — |
| onPointerUp | JSX.EventHandlerUnion<ElementFor<"button">, PointerEvent> | undefined | — | — |
| ref | JSX.HTMLElementTags["button"] extends { ref?: infer Ref; } ? Ref : never | undefined | — | — |
| size | "xs" | "sm" | "md" | "lg" | "xl" | "icon-xs" | "icon-sm" | "icon-md" | "icon-lg" | "icon-xl" | undefined | — | — |
| slotName | string | undefined | — | Root `data-slot` name |
| style | JSX.CSSProperties | undefined | — | — |
| styles | ButtonT.Styles | undefined | — | — |
| trailing | IconT.Name | — | Trailing visual content, usually an icon. |
| type | "button" extends "a" ? JSX.AnchorHTMLAttributes<HTMLAnchorElement>["type"] : "button" extends "button" ? JSX.ButtonHTMLAttributes<HTMLButtonElement>["type"] : "button" extends "input" ? JSX.InputHTMLAttributes<HTMLInputElement>["type"] : never | undefined | — | Native type attribute for supported native roots. |
| variant | "link" | "default" | "destructive" | "outline" | "secondary" | "ghost" | undefined | — | — |