Skip to content

    Button

    Triggers an action. Solid for the main action in a view, secondary for everything else, ghost for quiet actions in toolbars and rows, destructive (or destructive-soft) for destructive actions. glossy and destructive-glossy are raised versions of solid and destructive. iconOnly makes a square button with a required aria-label.

    React

    Preview

    Props

    • variant
    • size
    • iconOnly
    • shape
    • disabled
    • fullWidth
    • loading
    • loadingText
    • label
    • icon
    import { Button } from "@/components/ui/button"
    
    <Button>Save</Button>

    Usage

    When to use

    • Trigger an action on the current page: save, submit a form, open a dialog, delete an item.
    • Mark the one main action of a view with the solid variant.
    • Quiet actions that repeat on every row or sit in a toolbar, with the ghost variant. An icon alone, with iconOnly and a label for screen readers.

    When not to use

    • Going to another page. Use a link; for the look of a button, pass asChild and put the link inside, so it stays a real link.
    • Labels that are not actions, such as a status. Use Badge.

    Platform support

    What each platform has, from the spec. A selected platform is highlighted.

    NameWebiOSAndroidNote
    variantYesYesYesDeferred on iOS and Android: glossy, destructive-glossy.
    value of variant: glossyYesDeferredDeferred
    value of variant: destructive-glossyYesDeferredDeferred
    sizeYesYesYes
    iconOnlyYesYesYes
    shapeYesYesYes
    disabledYesYesYes
    asChildYesNoNoOnly on web. Not generated for iOS and Android.
    typeYesNoNoOnly on web. Not generated for iOS and Android.
    fullWidthYesYesYes
    leadingIconYesYesYes
    trailingIconYesYesYes
    loadingYesYesYes
    onPressNoYesYesOnly on iOS, Android.
    accessibilityLabelNoYesYesOnly on iOS, Android.
    loadingTextYesYesYes

    Variants

    variant

    solid: the main action, on the accent. secondary: neutral actions. ghost: neutral actions with no fill or border until hover, for toolbars, icon buttons and actions inside rows. destructive: destructive actions such as Delete, on the red solid with color-text-on-danger (4.53:1). destructive-soft: lighter destructive actions on the soft red fill. glossy: the main action, raised: the accent fill under a sheen lit from above, with inner edges and a med shadow. destructive-glossy: the same raised look on the red solid. soft: a strong action that is not the main one, on color-accent-muted with color-text-on-muted. link: a text-only action in running text, color-text-accent and always underlined, with no height or padding of its own.

    • soliddefault

    • secondary

    • soft

    • ghost

    • link

    • destructive

    • destructive-soft

    • glossy

    • destructive-glossy

    import { Button } from "@/components/ui/button"
    
    <Button>Save</Button>
    <Button variant="secondary">Save</Button>
    <Button variant="soft">Save</Button>
    <Button variant="ghost">Save</Button>
    <Button variant="link">Save</Button>
    <Button variant="destructive">Save</Button>
    <Button variant="destructive-soft">Save</Button>
    <Button variant="glossy">Save</Button>
    <Button variant="destructive-glossy">Save</Button>

    size

    Height from size-element-*: sm 28px, md 32px (the default), lg 36px, xl 44px with a mouse. On touch md grows to 36px, lg to 44px and xl to 48px; sm keeps its look and a 44px hit area. Use lg or xl for bigger targets, such as the main action of a mobile screen. Text is 14px in sm, 14px in md and lg, 16px in xl.

    • sm

    • mddefault

    • lg

    • xl

    import { Button } from "@/components/ui/button"
    
    <Button size="sm">Save</Button>
    <Button>Save</Button>
    <Button size="lg">Save</Button>
    <Button size="xl">Save</Button>

    shape

    default keeps the radius-element corner. circle draws an icon-only button as a true circle, as phones draw Back, More or Send in a bar: fill, border, pressed overlay and focus ring all take radius-full, with no corner smoothing, and the diameter is the element height. Only with iconOnly: a labelled Button keeps its radius-element corner, the web type and the native signatures reject circle without iconOnly, and development builds on the web log an error.

    • defaultdefault

    • circle

    import { IconPlus } from "@tabler/icons-react"
    import { Button } from "@/components/ui/button"
    
    <Button>Save</Button>
    <Button shape="circle" iconOnly aria-label="Save">
      <IconPlus size={16} />
    </Button>

    Examples

    Default

    import { Button } from "@/components/ui/button"
    
    <Button>Save</Button>

    With icon

    import { IconPlus } from "@tabler/icons-react"
    import { Button } from "@/components/ui/button"
    
    <Button variant="secondary">
      <IconPlus size={16} />
      New file
    </Button>

    Keeps link semantics (href, middle click) with button styles.

    import { Button } from "@/components/ui/button"
    
    <Button asChild variant="secondary">
      <a href="/docs">Read the docs</a>
    </Button>

    Icon only

    A quiet square button in a row or toolbar. aria-label names the action.

    import { IconDots } from "@tabler/icons-react"
    import { Button } from "@/components/ui/button"
    
    <Button variant="ghost" iconOnly aria-label="More actions">
      <IconDots size={16} />
    </Button>

    Round icon

    An icon-only button drawn as a circle, as in a phone's top bar or a send button. shape="circle" works only with iconOnly.

    import { IconArrowLeft, IconPlus } from "@tabler/icons-react"
    import { Button } from "@/components/ui/button"
    
    <div className="flex items-center gap-sm">
      <Button variant="ghost" iconOnly shape="circle" aria-label="Back">
        <IconArrowLeft size={16} />
      </Button>
      <Button iconOnly shape="circle" aria-label="New file">
        <IconPlus size={16} />
      </Button>
    </div>

    Glossy

    The main action, raised off the page. Use it in place of solid, not next to it.

    import { Button } from "@/components/ui/button"
    
    <Button variant="glossy" size="xl">Get started</Button>

    Disabled

    import { Button } from "@/components/ui/button"
    
    <Button disabled>Save</Button>

    Soft

    import { IconPlus } from "@tabler/icons-react"
    import { Button } from "@/components/ui/button"
    
    <Button variant="soft" leadingIcon={<IconPlus size={16} aria-hidden="true" />}>Add member</Button>

    No account yet?

    import { Button } from "@/components/ui/button"
    
    <p className="flex items-center gap-xs text-sm text-text-primary">
      No account yet?
      <Button variant="link">Create one</Button>
    </p>

    Loading

    import { IconDeviceFloppy } from "@tabler/icons-react"
    import { Button } from "@/components/ui/button"
    
    <div className="flex gap-sm">
      <Button loading loadingText="Saving" leadingIcon={<IconDeviceFloppy size={16} aria-hidden="true" />}>Save</Button>
      <Button variant="secondary" loading>Refresh</Button>
    </div>

    Trailing icon and full width

    import { IconArrowRight } from "@tabler/icons-react"
    import { Button } from "@/components/ui/button"
    
    <div className="w-full max-w-sm">
      <Button fullWidth trailingIcon={<IconArrowRight size={16} aria-hidden="true" />}>Continue</Button>
    </div>

    Do and don't

    Do

    • Use one solid button per view for the main action.
    • Use destructive or destructive-soft only for destructive actions, and say what is destroyed: Delete project, not OK.
    • Use destructive (solid) for the one main destructive action that can't be undone, such as the confirm button in a Delete project dialog. At most one per view.
    • Use destructive-soft for secondary or repeated destructive actions, such as Delete on each table row or in a menu.
    • Put the main action last in a button row (Cancel, then Save).
    • Use ghost for actions that repeat on every row or sit in a toolbar, so the page is not a wall of boxes.
    • Give every iconOnly button an aria-label that names the action (More actions, Close), and use a familiar icon.
    • Use glossy instead of solid when the main action should stand off the page, such as the call to action on a landing or empty state. It is still the one main action in its view.
    • Use destructive-glossy only where destructive would go: the one main destructive action of a view, in a view that already uses glossy.

    Don't

    • Don't restyle colors through className. Pick a variant. If none fits, open an issue instead of overriding it.
    • Don't use destructive for warnings or errors that are not an action.
    • Don't put destructive and destructive-soft side by side. The solid one loses its weight; pick one per group.
    • Don't use a button to navigate. Use asChild with a link so it is a real link.
    • Don't use ghost for the main action of a view: without a fill it does not read as the next step. Use solid.
    • Don't use iconOnly for an action the icon alone does not make clear. Show the label.
    • Don't put glossy and solid in the same view, or use glossy for secondary actions. A raised button reads as the main one; mixing the two looks like two styles, not two levels.
    • Don't use the glossy variants in dense UI (tables, toolbars, forms with many actions). The sheen and shadow are for one prominent action.

    Props

    NameTypeValuesDefaultDescription
    variantenumsolid | secondary | soft | ghost | link | destructive | destructive-soft | glossy | destructive-glossysolidsolid: the main action, on the accent. secondary: neutral actions. ghost: neutral actions with no fill or border until hover, for toolbars, icon buttons and actions inside rows. destructive: destructive actions such as Delete, on the red solid with color-text-on-danger (4.53:1). destructive-soft: lighter destructive actions on the soft red fill. glossy: the main action, raised: the accent fill under a sheen lit from above, with inner edges and a med shadow. destructive-glossy: the same raised look on the red solid. soft: a strong action that is not the main one, on color-accent-muted with color-text-on-muted. link: a text-only action in running text, color-text-accent and always underlined, with no height or padding of its own. Deferred on iOS and Android: glossy, destructive-glossy.
    sizeenumsm | md | lg | xlmdHeight from size-element-*: sm 28px, md 32px (the default), lg 36px, xl 44px with a mouse. On touch md grows to 36px, lg to 44px and xl to 48px; sm keeps its look and a 44px hit area. Use lg or xl for bigger targets, such as the main action of a mobile screen. Text is 14px in sm, 14px in md and lg, 16px in xl.
    iconOnlyboolean-falseSquare button that shows only an icon: as wide as it is tall, no label padding. Requires aria-label (the type enforces it). Pass the icon with the size of the button: 16 in sm, md and lg, 20 in xl.
    shapeenumdefault | circledefaultdefault keeps the radius-element corner. circle draws an icon-only button as a true circle, as phones draw Back, More or Send in a bar: fill, border, pressed overlay and focus ring all take radius-full, with no corner smoothing, and the diameter is the element height. Only with iconOnly: a labelled Button keeps its radius-element corner, the web type and the native signatures reject circle without iconOnly, and development builds on the web log an error.
    disabledboolean-falseNot interactive. Uses the neutral disabled look for every variant.
    asChildboolean-falseRender the child element (for example a link) with the button styles instead of a button. Only on web. Not generated for iOS and Android.
    typeenumbutton | submit | resetbuttonNative button type. Only on web. Not generated for iOS and Android.
    fullWidthboolean-falseFills the width of its container, such as the main action at the bottom of a mobile form.
    leadingIconnode--Tabler icon before the label. The way to put an icon in a button: loading swaps it for the spinner. Pass size 16 in sm, md and lg, 20 in xl, and aria-hidden.
    trailingIconnode--Tabler icon after the label, such as an arrow for a next step. Same size rule as leadingIcon.
    loadingboolean-falseWork in progress after a press. A Spinner takes the place of leadingIcon, or sits over the hidden label so the width holds. Sets aria-busy and aria-disabled, drops the click handler and forces type button, so presses and Enter are ignored with no client code; the button keeps focus, stays in the tab order and keeps its colors, with a progress cursor. Not supported with asChild: loading is ignored there, with a warning in development.
    onPressfunction--Called when the button is pressed. Not called while loading or disabled. Only on iOS, Android.
    accessibilityLabelstring--The name read by VoiceOver and TalkBack when the button shows only an icon. Required with iconOnly, as aria-label is on web: a Swift String, a Kotlin contentDescription. Without iconOnly the label slot is the name. Only on iOS, Android.
    loadingTextstring--Label while loading, such as Saving. It cross-fades with the label in place, the spinner arriving with it, and the button's width follows on the same clock; while loading it is the accessible name. Without it the label and name stay, under the spinner.

    Slots

    NameRequiredDescription
    labelyesShort verb or verb phrase, sentence case: Save, Delete project.
    iconnoOptional icon before or after the label.

    Anatomy

    PartDescription
    rootThe button element, or the child element when asChild is set.
    iconOptional Tabler icon before or after the label. 16px in sm, md and lg, 20px in xl (DESIGN.md 9.1). Colored by the variant.
    labelsWith loadingText only: one cell holding the idle label (leadingIcon and children) and the loading label (spinner and loadingText). Both stay mounted, start at the cell's start (the icon turns into the spinner on the same spot) and cross-fade over duration-fast with ease-standard. The cell's width is the idle label's box plus an invisible measure of the loading label, each running between 0 and its content on the same clock (interpolate-size), so the button and its neighbours slide to the new width instead of jumping; the cell clips the longer label while it moves. Under reduced motion, or where interpolate-size is unsupported, the width changes in one step and the fade remains. The hidden label is aria-hidden, and children are never copied.
    hitAreaTransparent ::before centered on the root, never smaller than size-target-min (24px on mouse, 44px on touch), so sm stays a 44px touch target.
    glossglossy and destructive-glossy only: a glass key lit from above. Over the fill, a flat face that turns lighter toward the bottom, and a light 1px rim all the way round, brightest along the top and the bottom, with a soft glow just inside the bottom edge. Drawn by the root's gloss-on-<solid> class, under the hover and pressed overlays.

    Accessibility

    Role: button

    KeysAction
    TabMoves focus to the button and shows the focus ring.
    Enter, SpaceActivates the button.
    • Defaults to type="button" so it never submits a form by accident. Pass type="submit" for form submits.
    • Disabled uses the native disabled attribute, so the button leaves the tab order and ignores clicks.
    • With asChild (for example a link), use aria-disabled instead of disabled. The disabled styles follow it.
    • An icon-only button needs an aria-label. With iconOnly the type requires it, so the code does not compile without one.
    • On iOS and Android an icon-only button requires accessibilityLabel, the native twin of aria-label, enforced by the generated signature.
    • shape="circle" changes only the outline. The name still comes from aria-label (accessibilityLabel on native), as for any icon-only button.
    • Pressed scales the button to scale-pressed. Under prefers-reduced-motion it does not move; the pressed overlay still shows.
    • The glossy variants keep the face under the label close to the solid: it only turns lighter below 55% of the height, about 0.05 white under the label's lowest line. With an accent near 4.5:1 for white text, check the label's lowest line on the glossy variant.
    • loading sets aria-busy and aria-disabled. The spinner is decorative. Without loadingText the button keeps its label as the name; with loadingText the name is the visible text. The button is not disabled while loading, so focus does not jump away, and it does not look disabled: colors stay, with the spinner and a progress cursor.

    Install

    npx werewolf-ui add button

    Run npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.