Checkbox

<wa-checkbox> Stable Since 2.0

Checkboxes let users toggle an option on or off, or select multiple items from a list. They also support an indeterminate state for partial selections in groups.

Checkbox

This component works with standard <form> elements. Please refer to the section on form controls to learn more about form submission and client-side validation.

Examples

Link to This Section

Checked

Link to This Section

Use the checked attribute to activate the checkbox.

Checked

The checked attribute is the initial value and does not reflect changes, consistent with native checkboxes. To toggle the checked state with JavaScript, use the checked property instead. To target checked checkboxes with CSS, use the :state(checked) selector.

Indeterminate

Link to This Section

Use the indeterminate attribute to make the checkbox indeterminate.

Indeterminate

Disabled

Link to This Section

Use the disabled attribute to disable the checkbox.

Disabled

Sizes

Link to This Section

Use the size attribute to change a checkbox's size.

Extra Small
Small
Medium
Large
Extra Large

Hint

Link to This Section

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

Label

Custom Validity

Link to This Section

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.

Check me
Submit

Importing

Link to This Section

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

CDN npm Self-Hosted React

Import this component directly from the CDN:

import 'https://ka-f.webawesome.com/[email protected]/components/checkbox/checkbox.js';

After installing Web Awesome via npm, import this component:

import '@awesome.me/webawesome/dist/components/checkbox/checkbox.js';

If you're self-hosting Web Awesome, import this component from your server:

import './webawesome/dist/components/checkbox/checkbox.js';

To import this component for React 18 or below, use the following code:

import WaCheckbox from '@awesome.me/webawesome/dist/react/checkbox/index.js';

Slots

Link to This Section

Learn more about using slots.

Attributes & Properties

Link to This Section

Learn more about attributes and properties.

Methods

Link to This Section

Learn more about methods.

Events

Link to This Section

Learn more about events.

CSS custom properties

Link to This Section

Learn more about CSS custom properties.

Custom States

Link to This Section

Learn more about custom states.

CSS parts

Link to This Section

Learn more about CSS parts.

Dependencies

Link to This Section

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

Need a hand? Report a bug Ask for help
    No results