Button

Button for triggering actions. Use default for the primary action on a surface, secondary/ghost for progressively lower emphasis, destructive for dangerous actions, and link for navigation-style actions. Content is provided via the default snippet; extra attributes (e.g. disabled, aria-*) are forwarded to the underlying element. Passing an href renders an <a> instead — a link that looks and lines up like a button, so a destination never has to be dressed up as an action with an onclick. status covers the life of an action that takes a moment: pending swaps the label for a spinner, success for a check. The label keeps its space while either is showing, so the button never changes width under the pointer that just pressed it — a button that resizes as it works throws the whole row around it, and on the press itself it moves the target out from under the finger.

Variants

default for the primary action on a surface, secondary for one sitting beside it, ghost for a toolbar or low-emphasis action, destructive for something irreversible, and link for a destination dressed as text rather than as a control.

Sizes

Every button in a row of controls is one height, so they line up without anyone choosing. icon only squares it off for a lone glyph — remember an aria-label there — and lg is reserved for a call to action standing on its own, never inside a toolbar row.

Status

The life of an action that takes a moment. The label goes invisible rather than being replaced, so the button holds its idle width while the spinner sits over it — a button that resizes as it works throws the whole row around it. Hold success briefly, then return to idle: a check that never goes away stops meaning anything.

Disabled

Pointer events are removed and opacity reduced. Reach for it only where the action is genuinely unavailable — a button that is disabled without saying why is a dead end.

API

Prop Type Default Description
children required import('svelte').Snippet

Button content.

variant 'default'|'destructive'|'secondary'|'ghost'|'link' 'default'

Visual emphasis of the button.

size 'default'|'lg'|'icon' 'default'

icon squares the button off for a lone glyph; lg is for a standalone call to action. The height is the same for the other two.

status 'idle'|'pending'|'success' 'idle'

Progress of the action this button started. pending shows a spinner, success a check; both keep the button's idle width.

class string

Additional Tailwind classes merged onto the button.

href string

Renders an <a> with the button's styling instead of a <button>.

onclick (event: MouseEvent) => void

Click event handler. Ignored when href is set.

type 'button'|'submit'|'reset' 'button'

Native button type attribute. Ignored when href is set.

disabled boolean

Disables the button (forwarded via ...rest).