Checkbox Group
Checkbox groups wrap a set of related checkboxes or switches so they share a label, hint, and grouping semantics.
Checkboxes in a group remain independent form controls with their own name, value, and validation. The group exists to provide a shared label, hint, and accessible grouping.
Examples
Labels
Use the label attribute to give the group an accessible label. For labels that contain HTML, use the label slot instead.
Hint
Add a descriptive hint to a checkbox group with the hint attribute. For hints that contain HTML, use the hint slot instead.
Orientation
Checkbox groups stack vertically by default. Set the orientation attribute to horizontal to lay them out in a row.
Sizes
The size of grouped checkboxes and switches is determined by the checkbox group's size attribute. Any size set on individual items will be overridden.
Disabling
A checkbox group itself can't be disabled. Add the disabled attribute to individual checkboxes to disable them.
Switches
A checkbox group also works with switches.
Required
The required attribute adds a visual indicator to the group's label. Because each checkbox is an independent control, the checkbox group doesn't enforce the requirement. Set the required property on the checkbox or call its setCustomValidity() method to control validation.
Importing
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.
Import this component directly from the CDN:
import 'https://ka-f.webawesome.com/webawesome@0.17.0/components/checkbox-group/checkbox-group.js';
After installing Web Awesome via npm, import this component:
import '@awesome.me/webawesome/dist/components/checkbox-group/checkbox-group.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/checkbox-group/checkbox-group.js';
To import this component for React 18 or below, use the following code:
import WaCheckboxGroup from '@awesome.me/webawesome/dist/react/checkbox-group/index.js';
Slots
Learn more about using slots.
| Name | Description |
|---|---|
| (default) | The default slot where <wa-checkbox> or <wa-switch> elements are placed. |
hint
|
Text that describes how to use the checkbox group. Alternatively, you can use the hint attribute. |
label
|
The checkbox group's label. Required for proper accessibility. Alternatively, you can use the label attribute. |
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects |
|---|---|---|
hinthint |
The checkbox group's hint. If you need to display HTML, use the
hint slot instead.
Type
string
Default
''
|
|
labellabel |
The checkbox group's label. Required for proper accessibility. If you need to display HTML, use the
label slot
instead.
Type
string
Default
''
|
|
orientationorientation |
The orientation in which to show grouped checkboxes.
Type
'horizontal' | 'vertical'
Default
'vertical'
|
|
requiredrequired |
Indicates that at least one option should be selected. This only adds a visual indicator to the label. To enforce
the requirement, use the
required attribute on the individual checkboxes and/or their setCustomValidity()
method.
Type
boolean
Default
false
|
|
sizesize |
The group's size. When present, this size will be applied to all
<wa-checkbox> and <wa-switch> items inside.
Type
'xs' | 's' | 'm' | 'l' | 'xl' | 'small' | 'medium' | 'large'
|
|
withHintwith-hint |
Only required for SSR. Set to
true if you're slotting in a hint element so the server-rendered markup includes
the hint before the component hydrates on the client.
Type
boolean
Default
false
|
|
withLabelwith-label |
Only required for SSR. Set to
true if you're slotting in a label element so the server-rendered markup includes
the label before the component hydrates on the client.
Type
boolean
Default
false
|
CSS Custom Properties
Learn more about CSS custom properties.
| Name | Description |
|---|---|
--gap |
The gap between grouped checkboxes.
Default
0.5em
|
CSS Parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
form-control |
The form control that wraps the label, group, and hint. |
::part(form-control)
|
form-control-input |
The element that wraps the grouped checkboxes, exposed as a role="group". |
::part(form-control-input)
|
form-control-label |
The label's wrapper. |
::part(form-control-label)
|
hint |
The hint's wrapper. |
::part(hint)
|
Dependencies
This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.