Buttons let people take an action with one tap. Material 3 gives five styles, and the one you pick
says how much weight the action carries on the screen: filled for the one action a screen is
about, tonal and elevated below it, outlined and text for everything secondary.
These apply to every variant. Their defaults come from size, so setting one overrides
the sizing for whatever size the button is. --np-button-shape is the exception worth
knowing: it sets the radius of the square shape only, so pair it with shape="square".
Round buttons stay pills, with a radius that follows their height.
A button renders a native <button>, or an <a> as soon as you
pass href, so the role, the keyboard and the focus ring come from the platform. Label
it with its text content wherever you can.
A button showing only an icon needs title. It becomes the accessible name and the
tooltip in one go. toggle reports the state through aria-pressed, loading sets aria-busy and names the spinner with loadingAriaLabel, and a disabled button is really disabled rather than dimmed.
Provides an accessibility label for the loading state.
title
string | null | undefined
undefined
Specifies the tooltip text.
size
'xs' | 's' | 'm' | 'l' | 'xl'
's'
Button size
shape
'round' | 'square'
'round'
Button shape
toggle
boolean | undefined
false
Enables toggle behavior, allowing the button to act as a toggleable (on/off) button.
selected
boolean | undefined
false
Indicates whether the button is currently selected (used with toggle buttons).
...attributes
HTMLButtonAttributes & HTMLAnchorAttributes
A single, unified set of <button> and <a> attributes.
Setting href renders an <a>, otherwise a <button>. Event handlers such as onclick receive event.currentTarget typed as HTMLButtonElement | HTMLAnchorElement, so you no longer need to set href to get correctly typed events.
A reference to the root DOM element of the component. This variable is bound using bind:this, allowing direct access to the underlying HTML element for manipulation or querying within
the component's logic.