button
Interactive control for form submission, dialogs, and user actions. The button element is the semantic choice for any clickable action that is not navigation.
When to Use
- Submitting or resetting a form
- Triggering JavaScript actions (opening dialogs, toggling states)
- Any interactive element that performs an action on the current page
Do not use buttons for navigation. Use <a href="..."> for links to other pages.
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 |
Code
Style Variants
Visual variants communicate hierarchy and importance.
Primary (Default)
High-emphasis actions. Use sparingly, typically once per section.
.secondary
Medium-emphasis actions. Outlined style that pairs with primary.
.ghost
Low-emphasis actions. Text-only style for tertiary actions.
Combined Example
Code
Size Variants
Size variations for different contexts.
| 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, form submit |
Code
Button States
Disabled
Use the disabled attribute to prevent interaction.
Focus State
Focus is indicated with an outline when navigating via keyboard. Tab through buttons to see the focus ring.
Code
Buttons with Icons
Buttons can include icons using the icon-wc component. The button's flexbox layout automatically handles alignment.
Code
Button in Forms
Buttons work seamlessly within form elements. For enhanced form fields, see the form-field custom element.
Code
Accessibility Notes
- 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 - Visible focus: The focus ring 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 have a minimum size of 44x44px for touch accessibility
Icon-Only Button
CSS Reference
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.
Related Elements
- a - For navigation; use
class="button"for button-styled links - form - Container for form controls including buttons
- input - Form inputs that buttons interact with
- form-field - Enhanced form field wrapper