Skip to main content Sidebar
On this page
Skip to table of contents

Checkbox

<pc-checkbox> 0.1.0 experimental

Checkboxes allow the user to toggle an option on or off.

Edit

This component works well with standard <form> elements. Please refer to the form controls page to learn more about form submission and client‐side validation.

Demos

Checked

Use the checked attribute to enable the checkbox.

Edit

Indeterminate

Use the indeterminate attribute to make the checkbox indeterminate.

Edit

Disabled

Use the disabled attribute to disable the checkbox.

Edit

Sizes

Use the size attribute to change the checkbox’s size.

Edit

Hint

Add a hint to a checkbox with the hint attribute. For hints that contain HTML, use the hint slot instead.

Edit

Custom validity

Use the setCustomValidity() method to set a custom validation message. This will prevent the form from submitting and make the browser display the error message you provide. To clear the error, call this function with an empty string.

Edit

Properties

NameDescriptionReflectsDefault
nameThe name of the checkbox, submitted as a name/value pair with form data.
Type: string
""
valueThe current value of the checkbox, submitted as a name/value pair with form data.
Type: string
""
sizeThe checkbox’s size.
Type: "small" | "medium" | "large"
"medium"
disabledDisables the checkbox.
Type: boolean
false
checkedChecks the checkbox off.
Type: boolean
false
indeterminateSets the checkbox’s state to indeterminate. This is usually applied to checkboxes that represent a “Select all/none” behaviour when associated checkboxes have a mix of checked and unchecked states.
Type: boolean
false
defaultCheckedThe default value of the checkbox. Primarily used for resetting the checkbox.
Type: boolean
false
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.
Type: string
""
requiredIndicates that the checkbox must be checked.
Type: boolean
false
hintThe checkbox’s hint. If you need to display HTML, use the hint slot instead.
Type: string
""
validityGets the validity state object.
validationMessageGets the validation message.
updateComplete A read‐only promise that resolves when the component has finished updating.

Learn more about customising animations.

Slots

NameDescription
(default)The checkbox’s label.
hintText that describes how to use the checkbox. Alternatively, you can use the hint attribute.

Learn more about using slots.

Methods

NameDescriptionArguments
click()Simulates a click on the checkbox.
focus()Focuses the checkbox.options: FocusOptions
blur()Unfocuses the checkbox (i.e., blurs it).
checkValidity()Checks for validity but does not 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 checkbox is invalid.
setCustomValidity()Sets a custom validation message. Pass an empty string to restore validity.message: string

Learn more about methods.

Events

NameDescriptionEvent detail
pc-inputEmitted when the checkbox receives input.
pc-changeEmitted when the checkbox’s state changes.
pc-focusEmitted when the checkbox gains focus.
pc-blurEmitted when the checkbox loses focus.
pc-invalidEmitted when the checkbox has been checked for validity and its constraints aren’t satisfied.

Learn more about events.

Parts

NameDescription
baseThe component’s base wrapper.
controlThe container that wraps the checkbox’s state.
checkbox-checkedMatches the control part when the checkbox is checked.
checkbox-indeterminateMatches the control part when the checkbox is indeterminate.
icon-checkedThe checked icon, a <pc-icon> element.
icon-indeterminateThe indeterminate icon, a <pc-icon> element.
labelThe container that wraps the checkbox’s label.
hintThe container that wraps the checkbox’s hint.

Learn more about customising CSS parts.

Importing

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/checkbox/checkbox.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/checkbox/checkbox.js";

To manually import this component from npm, copy this code snippet and paste it in your JavaScript file.

import "placer-toolkit/dist/components/checkbox/checkbox.js";

Dependencies

This component automatically imports these components:

We’d love to hear from you. Please reach out to us with any questions or enquiries you may have.

You can contact us via e‐mail at placer.coc.reports+contact@gmail.com.

We look forward to hearing from you!

Got it!
Dangerous lands

Whoa! You’ve wandered into the dangerous lands of Placer Toolkit. Version 0 is out of date and doesn’t meet EU privacy standards, including GDPR.

Want the latest powers, security and compliance? Stick with the current version of Placer Toolkit!

Yikes! Power up!

Our site is 100 % cookie‐free! We value your privacy, which is why we don’t store any cookies or personal information related to you.

Your browser history is safe from crumbs, and your data is protected, aligning with modern privacy standards like the GDPR. Enjoy your visit without a single digital cookie in sight! 🍪🚫

View our Privacy Policy for more information.

Got it!