button

Interactive control for form submission, dialogs, and user actions. Vanilla Breeze styles buttons with inline-flex layout, design tokens, and variant classes for visual hierarchy.

When to Use

  • Submitting or resetting a form
  • Triggering actions on the current page (opening dialogs, toggling states)
  • Any interactive element that performs an action rather than navigation

When NOT to Use

Do not use <button> for navigation. Use <a> instead. If you need a link that looks like a button, apply class="button" to an anchor element.

Style Variants

Visual variants communicate hierarchy and importance. Use primary for the main action, secondary for supporting actions, and ghost for tertiary or de-emphasized actions.

Class Appearance Use Case
(default / primary) Solid --color-interactive background, white text Primary action. Use sparingly, typically once per section
.secondary Transparent with colored border and text Supporting action that pairs with primary
.ghost No background or border, text-only Tertiary or de-emphasized actions

Sizes

Size variations accommodate different contexts, from compact inline actions to full-width form submissions.

Class Padding Font Size Use Case
.small xs / s sm Compact interfaces, inline actions
(default) s / m inherit Standard actions
.large m / l lg CTAs, hero sections
.full-width (inherits) (inherits) Full-width buttons, mobile form submit

Button Types

The type attribute determines the button's behavior within a form.

Type Behavior When to Use
button No default behavior JavaScript actions, dialogs, toggles
submit Submits the parent form (default in forms) Form submission
reset Resets form fields to initial values Clear form data

Buttons with Icons

Buttons can include icons using the icon-wc component. The button's inline-flex layout with gap: var(--size-xs) automatically handles alignment.

For icon-only buttons, always include aria-label to provide an accessible name.

Dialog Triggering

Buttons can open and close dialogs declaratively using the Invokers API. Point commandfor at the dialog's id and set command to show-modal or close. No JavaScript required.

Buttons in Forms

Buttons work seamlessly within form elements. Group actions in a <footer class="actions end"> to right-align them. For enhanced form fields, see the form-field custom element.

Button-Styled Links

Need a link that looks like a button? Use class="button" on an <a> element. All variants and sizes apply: .secondary, .ghost, .small, .large, .full-width.

See the <a> documentation for full examples and guidelines on when to use a link vs a button.

Accessibility

  • Always include text: Buttons should have visible text. For icon-only buttons, add aria-label
  • Use native buttons: Avoid <div onclick> patterns. Native buttons are keyboard accessible by default
  • Visible focus: The :focus-visible outline is essential for keyboard navigation. Do not remove it
  • Disabled state: Disabled buttons are not focusable. Consider keeping buttons enabled with validation messages instead
  • Minimum touch target: Buttons enforce a minimum size of var(--size-touch-min) (44x44px) for touch accessibility

CSS Reference

Related

  • a - For navigation; use class="button" for button-styled links
  • form - Container for form controls including buttons
  • dialog - Dialogs triggered by buttons via the Invokers API
  • menu - Menu of actions triggered by buttons
  • icon-wc - Icon component for buttons with icons
  • form-field - Enhanced form field wrapper