Skip to table of contents Button
<pc-button> 0.1.0 experimental Buttons represent actions that are available to the user.
<pc-button>Button</pc-button>
Use the appearance attribute to set the button’s appearance.
<pc-button appearance="neutral">Neutral</pc-button>
<pc-button appearance="primary">Primary</pc-button>
<pc-button appearance="success">Success</pc-button>
<pc-button appearance="warning">Warning</pc-button>
<pc-button appearance="danger">Danger</pc-button>
Use the variant attribute to set the button’s variant.
<div style="margin-block-end: var(--pc-spacing-m)">
<pc-button appearance="primary" variant="accent">Accent</pc-button>
<pc-button appearance="primary" variant="filled outlined">F + O</pc-button>
<pc-button appearance="primary" variant="filled">Filled</pc-button>
<pc-button appearance="primary" variant="outlined">Outlined</pc-button>
<pc-button appearance="primary" variant="plain">Plain</pc-button>
</div>
<div style="margin-block-end: var(--pc-spacing-m)">
<pc-button appearance="success" variant="accent">Accent</pc-button>
<pc-button appearance="success" variant="filled outlined">F + O</pc-button>
<pc-button appearance="success" variant="filled">Filled</pc-button>
<pc-button appearance="success" variant="outlined">Outlined</pc-button>
<pc-button appearance="success" variant="plain">Plain</pc-button>
</div>
<div style="margin-block-end: var(--pc-spacing-m)">
<pc-button appearance="neutral" variant="accent">Accent</pc-button>
<pc-button appearance="neutral" variant="filled outlined">F + O</pc-button>
<pc-button appearance="neutral" variant="filled">Filled</pc-button>
<pc-button appearance="neutral" variant="outlined">Outlined</pc-button>
<pc-button appearance="neutral" variant="plain">Plain</pc-button>
</div>
<div style="margin-block-end: var(--pc-spacing-m)">
<pc-button appearance="warning" variant="accent">Accent</pc-button>
<pc-button appearance="warning" variant="filled outlined">F + O</pc-button>
<pc-button appearance="warning" variant="filled">Filled</pc-button>
<pc-button appearance="warning" variant="outlined">Outlined</pc-button>
<pc-button appearance="warning" variant="plain">Plain</pc-button>
</div>
<div>
<pc-button appearance="danger" variant="accent">Accent</pc-button>
<pc-button appearance="danger" variant="filled outlined">F + O</pc-button>
<pc-button appearance="danger" variant="filled">Filled</pc-button>
<pc-button appearance="danger" variant="outlined">Outlined</pc-button>
<pc-button appearance="danger" variant="plain">Plain</pc-button>
</div>
Use the size attribute to change the button’s size.
<pc-button size="small">Small</pc-button>
<pc-button size="medium">Medium</pc-button>
<pc-button size="large">Large</pc-button>
Use the pill attribute to give buttons a pill‐shaped look.
<pc-button size="small" pill>Small</pc-button>
<pc-button size="medium" pill>Medium</pc-button>
<pc-button size="large" pill>Large</pc-button>
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 as an <a> under the hood. This gives you all the default link behaviour the browser provides (e.g., Ctrl or Shift + ) and exposes the target and download attributes.
<pc-button href="https://example.com">Link</pc-button>
<pc-button href="https://example.com" target="_blank">New window</pc-button>
<pc-button href="https://placer-toolkit.vercel.app/brand/logo.svg" download>Download</pc-button>
<pc-button href="https://example.com" disabled>Disabled</pc-button>
When a target is set, the link will receive rel="noreferrer noopener" for security reasons.
When only an icon is slotted into the default slot, the button becomes an icon button. In this case, it’s important to give the icon a label for users with assistive devices. Icon buttons can use any appearance or variant.
<div style="margin-block-end: var(--pc-spacing-m)">
<pc-button appearance="primary" variant="accent">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Accent"
></pc-icon>
</pc-button>
<pc-button appearance="primary" variant="filled outlined">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Filled + Outlined"
></pc-icon>
</pc-button>
<pc-button appearance="primary" variant="filled">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Filled"
></pc-icon>
</pc-button>
<pc-button appearance="primary" variant="outlined">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Outlined"
></pc-icon>
</pc-button>
<pc-button appearance="primary" variant="plain">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Plain"
></pc-icon>
</pc-button>
</div>
<div style="margin-block-end: var(--pc-spacing-m)">
<pc-button appearance="success" variant="accent">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Accent"
></pc-icon>
</pc-button>
<pc-button appearance="success" variant="filled outlined">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Filled + Outlined"
></pc-icon>
</pc-button>
<pc-button appearance="success" variant="filled">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Filled"
></pc-icon>
</pc-button>
<pc-button appearance="success" variant="outlined">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Outlined"
></pc-icon>
</pc-button>
<pc-button appearance="success" variant="plain">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Plain"
></pc-icon>
</pc-button>
</div>
<div style="margin-block-end: var(--pc-spacing-m)">
<pc-button appearance="neutral" variant="accent">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Accent"
></pc-icon>
</pc-button>
<pc-button appearance="neutral" variant="filled outlined">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Filled + Outlined"
></pc-icon>
</pc-button>
<pc-button appearance="neutral" variant="filled">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Filled"
></pc-icon>
</pc-button>
<pc-button appearance="neutral" variant="outlined">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Outlined"
></pc-icon>
</pc-button>
<pc-button appearance="neutral" variant="plain">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Plain"
></pc-icon>
</pc-button>
</div>
<div style="margin-block-end: var(--pc-spacing-m)">
<pc-button appearance="warning" variant="accent">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Accent"
></pc-icon>
</pc-button>
<pc-button appearance="warning" variant="filled outlined">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Filled + Outlined"
></pc-icon>
</pc-button>
<pc-button appearance="warning" variant="filled">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Filled"
></pc-icon>
</pc-button>
<pc-button appearance="warning" variant="outlined">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Outlined"
></pc-icon>
</pc-button>
<pc-button appearance="warning" variant="plain">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Plain"
></pc-icon>
</pc-button>
</div>
<div>
<pc-button appearance="danger" variant="accent">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Accent"
></pc-icon>
</pc-button>
<pc-button appearance="danger" variant="filled outlined">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Filled + Outlined"
></pc-icon>
</pc-button>
<pc-button appearance="danger" variant="filled">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Filled"
></pc-icon>
</pc-button>
<pc-button appearance="danger" variant="outlined">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Outlined"
></pc-icon>
</pc-button>
<pc-button appearance="danger" variant="plain">
<pc-icon
library="default"
icon-style="solid"
name="house"
label="Plain"
></pc-icon>
</pc-button>
</div>
As expected, buttons can be given a custom width by passing inline styles to the component (or using a class). This is useful for making buttons span the full width of their container on smaller screens.
<pc-button size="small" style="inline-size: 100%; margin-block-end: var(--pc-spacing-m)">Small</pc-button>
<pc-button size="medium" style="inline-size: 100%; margin-block-end: var(--pc-spacing-m)">Medium</pc-button>
<pc-button size="large" style="inline-size: 100%">Large</pc-button>
Use the prefix and suffix slots to add icons.
<div style="margin-block-end: var(--pc-spacing-m)">
<pc-button size="small">
<pc-icon
library="default"
icon-style="solid"
name="gear"
slot="prefix"
></pc-icon>
Settings
</pc-button>
<pc-button size="small">
<pc-icon
library="default"
icon-style="solid"
name="arrow-rotate-right"
slot="suffix"
></pc-icon>
Refresh
</pc-button>
<pc-button size="small">
<pc-icon
library="default"
icon-style="solid"
name="link"
slot="prefix"
></pc-icon>
Open
<pc-icon
library="default"
icon-style="solid"
name="arrow-up-right-from-square"
slot="suffix"
></pc-icon>
</pc-button>
</div>
<div style="margin-block-end: var(--pc-spacing-m)">
<pc-button size="medium">
<pc-icon
library="default"
icon-style="solid"
name="gear"
slot="prefix"
></pc-icon>
Settings
</pc-button>
<pc-button size="medium">
<pc-icon
library="default"
icon-style="solid"
name="arrow-rotate-right"
slot="suffix"
></pc-icon>
Refresh
</pc-button>
<pc-button size="medium">
<pc-icon
library="default"
icon-style="solid"
name="link"
slot="prefix"
></pc-icon>
Open
<pc-icon
library="default"
icon-style="solid"
name="arrow-up-right-from-square"
slot="suffix"
></pc-icon>
</pc-button>
</div>
<div>
<pc-button size="large">
<pc-icon
library="default"
icon-style="solid"
name="gear"
slot="prefix"
></pc-icon>
Settings
</pc-button>
<pc-button size="large">
<pc-icon
library="default"
icon-style="solid"
name="arrow-rotate-right"
slot="suffix"
></pc-icon>
Refresh
</pc-button>
<pc-button size="large">
<pc-icon
library="default"
icon-style="solid"
name="link"
slot="prefix"
></pc-icon>
Open
<pc-icon
library="default"
icon-style="solid"
name="arrow-up-right-from-square"
slot="suffix"
></pc-icon>
</pc-button>
</div>
Use the disabled attribute to disable a button.
<pc-button appearance="neutral" disabled>Neutral</pc-button>
<pc-button appearance="primary" disabled>Primary</pc-button>
<pc-button appearance="success" disabled>Success</pc-button>
<pc-button appearance="warning" disabled>Warning</pc-button>
<pc-button appearance="danger" disabled>Danger</pc-button>
This example demonstrates how to style buttons using a custom class. This is the recommended approach if you need to add additional appearances. To customise an existing appearance, modify the selector to target the button’s appearance attribute instead of a class (e.g., pc-button[appearance="primary"]).
<pc-button class="awesome-button">Awesome Button</pc-button>
<style>
pc-button.awesome-button::part(base) {
background-color: var(--pc-color-warning-fill-normal);
color: var(--pc-color-warning-on-normal);
border: var(--pc-border-width-m) var(--pc-border-style)
var(--pc-color-warning-border-normal);
border-radius: 0.5rem;
box-shadow: 0 0.25rem 0 var(--pc-color-warning-border-normal);
transition: none;
}
@media (hover: hover) {
pc-button.awesome-button::part(base):hover {
background-color: color-mix(
in oklab,
var(--pc-color-warning-fill-normal),
var(--pc-color-mix-hover)
);
color: color-mix(
in oklab,
var(--pc-color-warning-on-normal),
var(--pc-color-mix-hover)
);
border-color: color-mix(
in oklab,
var(--pc-color-warning-border-normal),
var(--pc-color-mix-hover)
);
box-shadow: 0 0.25rem 0 color-mix(
in oklab,
var(--pc-color-warning-border-normal),
var(--pc-color-mix-hover)
);
}
}
pc-button.awesome-button::part(base):active {
background-color: color-mix(
in oklab,
var(--pc-color-warning-border-normal),
var(--pc-color-mix-hover)
);
color: color-mix(
in oklab,
var(--pc-color-warning-on-normal),
var(--pc-color-mix-hover)
);
border-color: color-mix(
in oklab,
var(--pc-color-warning-border-normal),
var(--pc-color-mix-hover)
);
box-shadow: none;
translate: 0 0.25rem;
}
</style>
| Name | Description | Reflects | Default |
|---|
appearance | The button’s appearance.
Type: "primary"
| "success"
| "neutral"
| "warning"
| "danger"
| "text" |
| "neutral" |
variant | The button’s variant.
Type: "accent"
| "filled"
| "outlined"
| "plain" |
| "accent" |
size | The button’s size.
Type: "small" | "medium" | "large" |
| "medium" |
disabled | Disables the button.
Type: boolean |
| false |
pill | Draws a pill‐style button.
Type: boolean |
| false |
type | The 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.
Type: "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.
Type: 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 the href attribute is present.
Type: string |
| "" |
href | When set, the underlying button will be rendered as an <a> with this href instead of a <button>.
Type: string |
| "" |
target | Tells the browser where to open the link. It should only be used when the href attribute is present.
Type: "_blank" | "_parent" | "_self" | "_top" | undefined |
| ‐ |
rel | When using the href attribute, this attribute will map to the underlying link’s rel attribute. Unlike regular links, the default set for this attribute is noreferrer noopener to prevent security exploits. However, if you’re using target to point to a specific tab or window, this will prevent that from working properly. You can remove or change the default value by setting the attribute to an empty string or a value of your choice, respectively.
Type: string |
| "noreferrer noopener" |
download | Tells the browser to download the linked file as this file name. Only used when the href attribute is present.
Type: string | undefined |
| ‐ |
form | This is 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.
Type: string | undefined |
| ‐ |
formAction
formaction | Used to override the form owner’s action attribute.
Type: string | undefined |
| ‐ |
formEnctype
formenctype | Used to override the form owner’s enctype attribute.
Type: "application/x-www-form-url-encoded"
| "multipart/form-data"
| "text/plain" | undefined |
| ‐ |
formMethod
formmethod | Used to override the form owner’s method attribute.
Type: "GET" | "POST" | undefined |
| ‐ |
formNoValidate
formnovalidate | Used to override the form owner’s novalidate attribute.
Type: boolean | undefined |
| ‐ |
formTarget
formtarget | Used to override the form owner’s target attribute.
Type: "_self"
| "_blank"
| "_parent"
| "_top"
| string | undefined |
| ‐ |
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 customising animations.
| 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.
| Name | Description | Arguments |
|---|
click() | Simulates a click on the button. | ‐ |
focus() | Focuses the button. | options: FocusOptions |
blur() | Unfocuses the button (i.e., blurs it). | ‐ |
checkValidity() | Checks for validity but doesn’t show a validation message. Returns true when valid and false when 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.
| Name | Description | Event detail |
|---|
pc-focus | Emitted when the button gains focus. | ‐ |
pc-blur | Emitted when the button loses focus (i.e., is blurred). | ‐ |
pc-invalid | Emitted when the form control has been checked for validity and its constraints aren’t satisfied. | ‐ |
Learn more about events.
| 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. |
Learn more about customising CSS parts.
If you’re using the autoloader or the standard loader,
you can skip this section. But if you’re cherry picking,
you can use any of the following snippets to import this component.
CDN (script tag)CDN (import)npm (import)
To manually import this component from the CDN,
copy this code snippet and paste it in your HTML.
<script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.3/cdn/components/button/button.js"></script>
To manually import this component from the CDN, copy
this code snippet and paste it in your JavaScript file.
import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.3/cdn/components/button/button.js";
To manually import this component from npm, copy this
code snippet and paste it in your JavaScript file.
import "placer-toolkit/dist/components/button/button.js";