Button

Save, submit, or move to the next step. Give users a clear action for the task they want to complete.

Live preview
Save

Press the button to try it.

View code
HTML
<sy-button variant="primary" size="medium">Save</sy-button>

Usage guide

#

Use a Button to execute the user's choice. Use links for navigation. Within one task area, emphasize the most important action first.

Primary action

For save and submit, use primary to make the next action clear.

Secondary action

For cancel and back, use default or secondary.

Lightweight action

For supplementary features, use borderless to reduce emphasis.

Use loading for actions in progress and disabled for unavailable actions.

Feature examples

#

Choose a feature from 14 topics. Explore property settings, method calls, event results, and slot layouts through live examples and code.

Usage examples · Overview (Dev)

Try the selected example. Topics with multiple configurations let you switch between detailed examples.

View code
HTML
Loading the example.

Usage examples · Overview

Try the selected example. Topics with multiple configurations let you switch between detailed examples.

View code
HTML
Loading the example.

Property · Disabled

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Form validation

Regular submission is blocked when required fields are empty. A button with formnovalidate skips this check, useful for saving incomplete drafts. Keep server-side validation in place.

View code
HTML
Loading the example.

Property · Full Width

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Loading

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Size

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Type

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Variant

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Methods · Method / setBlur&setFocus

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · Method / setClick

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Events · Click

Interact with the component to see event names and payloads in the live preview below.

View code
HTML
Loading the example.

Slot ·

Compare the content placed inside the component with its slot names in the code.

View code
HTML
Loading the example.

Usage examples · Icon button tooltip

Label an icon-only action with a tooltip shown on hover or focus.

View code
HTML
<sy-button icon-only tooltip="Add an item"><svg
    width="16"
    height="16"
    viewBox="0 0 24 24"
    fill="none"
    stroke="currentColor"
    stroke-width="1.8"
    aria-hidden="true"
  >
    <path d="M12 5v14M5 12h14" />
  </svg></sy-button>

API reference

#

Hover over a name or focus it with the keyboard to see an example. On touch screens, tap the name.

Properties

AttributeTypeDefaultDescription
default | primary | secondary | borderlessdefaultVisual style of the button
small | medium | largemediumButton size
booleanfalseBlock clicks and keyboard activation
booleanfalseShow progress and block additional clicks
booleanfalseFill the parent's width
booleanfalseConfigure an icon-only button. Place only an icon in the slot
string""Default tooltip. Accessible name for an icon-only button
button | submit | resetbuttonStandard action, form submission, or reset
booleanfalseSkip form validation on submit

Slots

NameDescription
Button text and icons. Add them as child elements without a slot name.

Methods

MethodReturnsDescription
Promise<void>Click the internal button. Does not run when disabled or loading
Promise<void>Focus the internal button
Promise<void>Remove focus from the internal button
Promise<void>Update the group direction and the shape of the first and last buttons. In normal use, sy-button-group manages this, so place the button inside a group.

Events

EventDescription
The standard click event for a button. Subscribe with addEventListener. Handle form submission in the form's submit event.
The examples below target a button with id="action-button".
JavaScript
const button = document.querySelector('#action-button');
await customElements.whenDefined('sy-button');
button.addEventListener('click', () => {
  console.log('Button clicked.');
});
await button.setFocus();