<cs-button>
StableActionsSince 0.1

Buttons represent actions the user can take, such as submitting a form, opening a dialog, or navigating to another page.

Save
Settings

Examples

Variant

Use the variant attribute to set the button’s semantic variant.

Neutral Brand Success Warning Danger

Appearance

Use the appearance attribute to change the button’s visual appearance. Pair it with any variant for the full matrix.

Accent Filled-Outlined Filled Outlined Plain
Accent Filled-Outlined Filled Outlined Plain
Accent Filled-Outlined Filled Outlined Plain
Accent Filled-Outlined Filled Outlined Plain
Accent Filled-Outlined Filled Outlined Plain

Size

Use the size attribute to change a button’s size.

Extra Small Small Medium Large Extra Large

Pill

Use the pill attribute to give buttons rounded edges.

Pill Button

Set the href attribute to render the button as an <a> under the hood. Provides all the browser’s native link behavior (e.g. CMD/CTRL/SHIFT + CLICK) plus the rel, target, and download attributes.

Link New Window Download

Icon Button

When an icon is the only thing slotted into the label, the button becomes an icon button. Icon buttons work with any appearance or variant.

Give icon-only buttons a label.
With no text to announce, a screen reader has nothing to read. Add label to the icon (<cs-icon name="home" label="Home">) so the button has an accessible name.

Start & End Decorations

Use the start and end slots to add presentational elements like <cs-icon> beside the button label.

Settings Refresh Open

Caret

Use the with-caret attribute to add a dropdown indicator when a button triggers a dropdown, menu, or popover.

Options

Loading

Use the loading attribute to put a button in a busy state. Its width stays the same, so adjacent elements don’t shift.

Brand Success Neutral Warning Danger

Disabled

Use the disabled attribute to disable a button. It works on link buttons too.

Brand Success Neutral Warning Danger
Link New Window Download

Custom Width

Give a button a custom width to size it independently of its content — useful for making buttons span their container on smaller screens.

Save

Customizing

Target the button part to restyle a button from the outside. Use a custom class when you’re adding a new variation; to retheme an existing one, target its variant attribute instead (e.g. cs-button[variant="brand"]).

Build the override out of design tokens rather than literal values, as below — a hue’s tint scale gives you coordinated light and dark edges for free, and the radius, border width and spacing all have a step on the scale. Tokens are also what keeps a customization working across themes and colour schemes.

Pink Button

API

Importing

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.

npm Self-Hosted React
import '@cruglobal/cornerstone-components/components/button/button.js';
import './cornerstone/components/button/button.js';
import CsButton from '@cruglobal/cornerstone-components/react/button/index.js';

Slots

Learn more about using slots.

NameDescription
(default)The button's label.
endAn element, such as <cs-icon>, placed after the label.
startAn element, such as <cs-icon>, placed before the label.

Attributes & Properties

Learn more about attributes and properties.

PropertyAttributeDescriptionTypeDefaultReflects
appearanceappearanceThe button's visual appearance.'accent' | 'filled' | 'outlined' | 'filled-outlined' | 'plain''accent'Yes
disableddisabledDisables the button.booleanfalse
downloaddownloadTells the browser to download the linked file as this filename. Only used when href is present.string | undefined
formBy default, form controls are associated with the nearest containing <form> element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work.HTMLFormElement | null
formActionformactionUsed to override the form owner's action attribute.string
formEnctypeformenctypeUsed to override the form owner's enctype attribute.'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/plain'
formMethodformmethodUsed to override the form owner's method attribute.'post' | 'get'
formNoValidateformnovalidateUsed to override the form owner's novalidate attribute.boolean
formTargetformtargetUsed to override the form owner's target attribute.'_self' | '_blank' | '_parent' | '_top' | string
hrefhrefWhen set, the underlying button will be rendered as an <a> with this href instead of a <button>.stringYes
loadingloadingDraws the button in a loading state.booleanfalseYes
namenameThe 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 href is present.string | nullnullYes
pillpillDraws a pill-style button with rounded edges.booleanfalseYes
relrelWhen using href, this attribute will map to the underlying link's rel attribute.string | undefined
sizesizeThe button's size.'xs' | 's' | 'm' | 'l' | 'xl''m'Yes
targettargetTells the browser where to open the link. Only used when href is present.'_blank' | '_parent' | '_self' | '_top'
typetypeThe type of button. Note that the default value is button instead of submit, which is opposite of how native <button> elements behave. When the type is submit, the button will submit the surrounding form.'button' | 'submit' | 'reset''button'
validationTargetOverride this to change where constraint validation popups are anchored.undefined | HTMLElement
validatorsValidators are static because they have observedAttributes, essentially attributes to "watch" for changes. Whenever these attributes change, we want to be notified and update the validator.Validator[][]
valuevalueThe 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 href is present.stringYes
variantvariantThe button's theme variant. Defaults to neutral if not within another element with a variant.'neutral' | 'brand' | 'highlight' | 'information' | 'success' | 'warning' | 'danger''neutral'Yes
withCaretwith-caretDraws the button with a caret. Used to indicate that the button triggers a dropdown menu or similar behavior.booleanfalseYes

Methods

Learn more about methods.

NameDescriptionArguments
blur()Removes focus from the button.
click()Simulates a click on the button.
focus()Sets focus on the button.options: FocusOptions
formStateRestoreCallback()Called when the browser is trying to restore element’s state to state in which case reason is "restore", or when the browser is trying to fulfill autofill on behalf of user in which case reason is "autocomplete". In the case of "restore", state is a string, File, or FormData object previously set as the second argument to setFormValue.state: string | File | FormData | null, reason: 'autocomplete' | 'restore'
resetValidity()Reset validity is a way of removing manual custom errors and native validation.
setCustomValidity()Do not use this when creating a "Validator". This is intended for end users of components. We track manually defined custom errors so we don't clear them on accident in our validators.message: string

Events

Learn more about events.

NameDescription
blurEmitted when the button loses focus.
cs-invalidEmitted when the form control has been checked for validity and its constraints aren't satisfied.
focusEmitted when the button gains focus.

Custom States

Learn more about custom states.

NameDescriptionCSS selector
disabledApplied when the button is disabled.:state(disabled)
icon-buttonApplied when the button contains only a <cs-icon> with no other content.:state(icon-button)
linkApplied when the button is rendered as a link (i.e. href is set).:state(link)
loadingApplied when the button is in the loading state.:state(loading)

CSS Parts

Learn more about CSS parts.

NameDescriptionCSS selector
buttonThe component's outer wrapper.::part(button)
caretThe button's caret icon, a <cs-icon> element.::part(caret)
endThe container that wraps the end slot.::part(end)
labelThe button's label.::part(label)
spinnerThe spinner that shows when the button is in the loading state.::part(spinner)
startThe container that wraps the start slot.::part(start)

Dependencies

This component automatically imports the following elements. Sub-dependencies, if any exist, are included in this list.