Button
<sl-button> | SlButton
            Buttons represent actions that are available to the user.
<sl-button>Button</sl-button>
Variants
            Use the variant attribute to set the button’s variant. Primary, sceondary and teriary are the
            core button variants. Use the primary button to call attention to an action on a form or highlight the
            strongest call to action on a page. Primary buttons should only appear once per container. Use the Use
            tertiary buttons where a group of buttons is needed.
          
<sl-button variant="primary">Primary</sl-button> <sl-button variant="secondary">Secondary</sl-button> <sl-button variant="tertiary">Tertiary</sl-button> <sl-button variant="naked">Naked</sl-button> <div style="background: var(--hds-color-bg-primary, #283D84); display: inline-flex; padding: 5px;"> <sl-button variant="on-dark">On Dark</sl-button> </div> <sl-button variant="on-light">On Light</sl-button> <sl-button variant="extra">Extra</sl-button>
Contextual variants
Use contextual buttons when appropriate to call attention to an action.
<sl-button variant="neutral">Neutral</sl-button> <sl-button variant="success">Success</sl-button> <sl-button variant="warning">Warning</sl-button> <sl-button variant="danger">Danger</sl-button>
Sizes
            Use the size attribute to change a button’s size, which affects its height and text size. There
            are three available sizes: small, medium (default), and large.
          
<sl-button size="small">Small</sl-button> <sl-button size="medium">Medium</sl-button> <sl-button size="large">Large</sl-button>
Outline buttons
Use the outline attribute to draw outlined buttons with transparent backgrounds.
<sl-button variant="primary" outline>Primary</sl-button> <sl-button variant="neutral" outline>Neutral</sl-button> <sl-button variant="success" outline>Success</sl-button> <sl-button variant="warning" outline>Warning</sl-button> <sl-button variant="danger" outline>Danger</sl-button>
Pill buttons
Use the pill attribute to give buttons rounded edges.
<sl-button size="small" pill>Small</sl-button> <sl-button size="medium" pill>Medium</sl-button> <sl-button size="large" pill>Large</sl-button>
Minimum Width
Each button size has a minimum width to help accommodate a balanced look for shorter labels. It can be turned on or off at project level.
- Small buttons: 64px minimum width
- Medium buttons: 80px minimum width
- Large buttons: 104px minimum width These minimum widths ensure buttons maintain a consistent appearance when used with short labels.
<div style="display: flex; flex-direction: column; gap: 1rem;"> <div> <sl-button size="small">Small</sl-button> </div> <div> <sl-button>Default</sl-button> </div> <div> <sl-button size="large">Large</sl-button> </div> </div>
Buttons with Icons
            Icons can be added to buttons using the prefix and suffix slots. It’s recommended
            to use only one icon per button.
          
<div style="display: flex; flex-direction: column; gap: 1rem;"> <div style="display: flex; gap: 1rem;"> <sl-button size="small"> <sl-icon slot="prefix" name="arrow-left"></sl-icon> Back </sl-button> <sl-button size="small"> Next <sl-icon slot="suffix" name="arrow-right"></sl-icon> </sl-button> <sl-button size="medium"> <sl-icon slot="prefix" name="arrow-left"></sl-icon> Back </sl-button> <sl-button size="medium"> Next <sl-icon slot="suffix" name="arrow-right"></sl-icon> </sl-button> </div> </div>
Icon buttons
            Use the icon attribute to create circular icon buttons. When this attribute is set, the button
            expects a single <sl-icon> in the default slot.
          
<sl-button variant="secondary" size="small" icon> <sl-icon name="gear" label="Settings"></sl-icon> </sl-button> <sl-button variant="secondary" size="medium" icon> <sl-icon name="gear" label="Settings"></sl-icon> </sl-button> <sl-button variant="secondary" size="large" icon> <sl-icon name="gear" label="Settings"></sl-icon> </sl-button>
Opacity text buttons
            Use the dark or light variant to create text buttons that share the same size as
            regular buttons but don’t have backgrounds or borders. Dark or Light use opacity and are for use on colored
            backgrounds.
          
<div style="background: grey"> <sl-button variant="dark" size="medium">Dark</sl-button> <sl-button variant="light" size="medium">Light</sl-button> </div>
Link buttons
            It’s often helpful to have a button that works like a link. This is possible by setting the
            href attribute, which will make the component render an <a> under the hood.
            This gives you all the default link behavior the browser provides (e.g. CMD/CTRL/SHIFT +
            CLICK) and exposes the target and download attributes.
          
<sl-button href="https://example.com/">Link</sl-button> <sl-button href="https://example.com/" target="_blank">New Window</sl-button> <sl-button href="/assets/images/wordmark.svg" download="shoelace.svg">Download</sl-button> <sl-button href="https://example.com/" disabled>Disabled</sl-button>
              When a target is set, the link will receive rel="noreferrer noopener" for
              security reasons.
            
Setting a custom width
            As expected, buttons can be given a custom width by setting the width attribute. This is useful
            for making buttons span the full width of their container on smaller screens.
          
<!-- Full-width buttons --> <sl-button style="--width: 100%; margin-bottom: 1rem;" variant="secondary" size="small">Full Width Small</sl-button> <sl-button style="--width: 100%; margin-bottom: 1rem;" variant="secondary" size="medium">Full Width Medium</sl-button> <sl-button style="--width: 100%; margin-bottom: 1rem;" variant="secondary" size="large">Full Width Large</sl-button> <!-- Custom width buttons --> <div style="margin-top: 1rem;"> <sl-button style="--width: 200px;" variant="primary">200px Width</sl-button> </div>
Prefix and suffix icons
Use the prefix and suffix slots to add icons.
<sl-button variant="secondary" size="small"> <sl-icon slot="prefix" name="gear"></sl-icon> Settings </sl-button> <sl-button variant="secondary" size="small"> <sl-icon slot="suffix" name="arrow-rotate-left"></sl-icon> Refresh </sl-button> <sl-button variant="secondary" size="small"> <sl-icon slot="prefix" name="link"></sl-icon> <sl-icon slot="suffix" name="arrow-up-right-from-square"></sl-icon> Open </sl-button> <br /><br /> <sl-button variant="secondary"> <sl-icon slot="prefix" name="gear"></sl-icon> Settings </sl-button> <sl-button variant="secondary"> <sl-icon slot="suffix" name="arrow-rotate-left"></sl-icon> Refresh </sl-button> <sl-button variant="secondary"> <sl-icon slot="prefix" name="link"></sl-icon> <sl-icon slot="suffix" name="arrow-up-right-from-square"></sl-icon> Open </sl-button> <br /><br /> <sl-button variant="secondary" size="large"> <sl-icon slot="prefix" name="gear"></sl-icon> Settings </sl-button> <sl-button variant="secondary" size="large"> <sl-icon slot="suffix" name="arrow-rotate-left"></sl-icon> Refresh </sl-button> <sl-button variant="secondary" size="large"> <sl-icon slot="prefix" name="link"></sl-icon> <sl-icon slot="suffix" name="arrow-up-right-from-square"></sl-icon> Open </sl-button>
Caret
            Use the caret attribute to add a dropdown indicator when a button will trigger a dropdown,
            menu, or popover.
          
<sl-button size="small" caret>Small</sl-button> <sl-button size="medium" caret>Medium</sl-button> <sl-button size="large" caret>Large</sl-button>
Loading
            Use the loading attribute to make a button busy. The width will remain the same as before,
            preventing adjacent elements from moving around.
          
<sl-button variant="primary" loading>Primary</sl-button> <sl-button variant="secondary" loading>Secondary</sl-button> <sl-button variant="tertiary" loading>Tertiary</sl-button> <sl-button variant="neutral" loading>Neutral</sl-button> <sl-button variant="success" loading>Success</sl-button> <sl-button variant="warning" loading>Warning</sl-button> <sl-button variant="danger" loading>Danger</sl-button>
Disabled
Use the disabled attribute to disable a button.
<sl-button variant="primary" disabled>Primary</sl-button> <sl-button variant="secondary" disabled>Secondary</sl-button> <sl-button variant="tertiary" disabled>Tertiary</sl-button> <sl-button variant="neutral" disabled>Neutral</sl-button> <sl-button variant="success" disabled>Success</sl-button> <sl-button variant="warning" disabled>Warning</sl-button> <sl-button variant="danger" disabled>Danger</sl-button>
Styling buttons
            This example demonstrates how to style buttons using a custom class. This is the recommended approach if you
            need to add additional variations. To customize an existing variation, modify the selector to target the
            button’s variant attribute instead of a class (e.g. sl-button[variant="primary"]).
          
<sl-button class="pink">Pink Button</sl-button> <style> sl-button.pink::part(base) { /* Set design tokens for height and border width */ --sl-input-height-medium: 48px; --sl-input-border-width: 4px; border-radius: 0; background-color: #ff1493; border-top-color: #ff7ac1; border-left-color: #ff7ac1; border-bottom-color: #ad005c; border-right-color: #ad005c; color: white; font-size: 1.125rem; box-shadow: 0 2px 10px #0002; transition: var(--sl-transition-medium) transform ease, var(--sl-transition-medium) border ease; } sl-button.pink::part(base):hover { transform: scale(1.05) rotate(-1deg); } sl-button.pink::part(base):active { border-top-color: #ad005c; border-right-color: #ff7ac1; border-bottom-color: #ff7ac1; border-left-color: #ad005c; transform: scale(1.05) rotate(-1deg) translateY(2px); } sl-button.pink::part(base):focus-visible { outline: dashed 2px deeppink; outline-offset: 4px; } </style>
Slots
| Name | Description | 
|---|---|
| (default) | The button’s label. | 
| prefix | A presentational prefix icon or similar element. | 
| suffix | A presentational suffix icon or similar element. | 
Learn more about using slots.
Properties
| Name | Description | Reflects | Type | Default | 
|---|---|---|---|---|
| variant | The button’s theme variant. |  | 
                      'primary' | 'secondary' | 'tertiary' | 'naked' | 'on-dark' | 'on-light' | 'extra' | 'neutral' |
                      'dark' | 'light' | 'success' | 'warning' | 'danger' | 'primary' | 
| size | The button’s size. |  | 'small' | 'medium' | 'large' | 'medium' | 
| caret | Draws the button with a caret. Used to indicate that the button triggers a dropdown menu or similar behavior. |  | boolean | false | 
| dots | Draws the button with a dots. Used to indicate that the button triggers a dropdown menu or similar behavior. |  | boolean | false | 
| disabled | Disables the button. |  | boolean | false | 
| loading | Draws the button in a loading state. |  | boolean | false | 
| outline | Draws an outlined button. |  | boolean | false | 
| pill | Draws a pill-style button with rounded edges. |  | boolean | false | 
| icon | Draws a circular icon button. When this attribute is present, the button expects a single <sl-icon>in the default slot. |  | boolean | false | 
| type | The type of button. Note that the default value is buttoninstead ofsubmit, which is opposite of how native<button>elements behave.
                    When the type issubmit, the button will submit the surrounding form. | 'button' | 'submit' | 'reset' | 'button' | |
| name | The name of the button, submitted as a name/value pair with form data, but only when this button is
                    the submitter. This attribute is ignored when hrefis present. | string | '' | |
| value | The value of the button, submitted as a pair with the button’s name as part of the form data, but
                    only when this button is the submitter. This attribute is ignored when hrefis present. | string | '' | |
| href | When set, the underlying button will be rendered as an <a>with thishrefinstead of a<button>. | string | '' | |
| target | Tells the browser where to open the link. Only used when hrefis present. | '_blank' | '_parent' | '_self' | '_top' | - | |
| rel | When using href, this attribute will map to the underlying link’srelattribute. Unlike regular links, the default isnoreferrer noopenerto
                    prevent security exploits. However, if you’re usingtargetto point to a specific
                    tab/window, this will prevent that from working correctly. You can remove or change the default
                    value by setting the attribute to an empty string or a value of your choice, respectively. | string | 'noreferrer noopener' | |
| download | Tells the browser to download the linked file as this filename. Only used when hrefis
                    present. | string | undefined | - | |
| form | The “form owner” to associate the button with. If omitted, the closest containing form will be used instead. The value of this attribute must be an id of a form in the same document or shadow root as the button. | string | - | |
| formAction formaction  | Used to override the form owner’s actionattribute. | string | - | |
| formEnctype formenctype  | Used to override the form owner’s enctypeattribute. | 'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/plain' | - | |
| formMethod formmethod  | Used to override the form owner’s methodattribute. | 'post' | 'get' | - | |
| formNoValidate formnovalidate  | Used to override the form owner’s novalidateattribute. | boolean | - | |
| formTarget formtarget  | Used to override the form owner’s targetattribute. | '_self' | '_blank' | '_parent' | '_top' | string | - | |
| validity | Gets the validity state object | - | - | |
| validationMessage | Gets the validation message | - | - | |
| updateComplete | A read-only promise that resolves when the component has finished updating. | 
Learn more about attributes and properties.
Events
| Name | React Event | Description | Event Detail | 
|---|---|---|---|
| sl-blur |  | Emitted when the button loses focus. | - | 
| sl-focus |  | Emitted when the button gains focus. | - | 
| sl-invalid |  | Emitted when the form control has been checked for validity and its constraints aren’t satisfied. | - | 
Learn more about events.
Methods
| Name | Description | Arguments | 
|---|---|---|
| click() | Simulates a click on the button. | - | 
| focus() | Sets focus on the button. |  options: FocusOptions  | 
| blur() | Removes focus from the button. | - | 
| checkValidity() | Checks for validity but does not show a validation message. Returns truewhen valid andfalsewhen invalid. | - | 
| getForm() | Gets the associated form, if one exists. | - | 
| reportValidity() | Checks for validity and shows the browser’s validation message if the control is invalid. | - | 
| setCustomValidity() | Sets a custom validation message. Pass an empty string to restore validity. |  message: string  | 
Learn more about methods.
Parts
| Name | Description | 
|---|---|
| base | The component’s base wrapper. | 
| prefix | The container that wraps the prefix. | 
| label | The button’s label. | 
| suffix | The container that wraps the suffix. | 
| caret | The button’s caret icon, an <sl-icon>element. | 
| spinner | The spinner that shows when the button is in the loading state. | 
Learn more about customizing CSS parts.
Dependencies
This component automatically imports the following dependencies.
- <sl-icon>
- <sl-spinner>