Checkbox Group
View as MarkdownCoordinate a group of native checkboxes. Custom element
<ui-checkbox-group aria-labelledby="features-label"> <span id="features-label">Features</span> <label class="ui-choice"> <input class="ui-checkbox" type="checkbox" name="features" value="documentation" checked> <span data-ui-part="body">Documentation</span></label> <label class="ui-choice"> <input class="ui-checkbox" type="checkbox" name="features" value="playground"> <span data-ui-part="body">Playground</span></label></ui-checkbox-group><fieldset class="ui-choice-group"> <legend class="ui-label">Notifications</legend>
<label class="ui-choice" for="notifications-product"> <input class="ui-checkbox" id="notifications-product" name="notifications" type="checkbox" value="product" checked> <span data-ui-part="body"> <span data-ui-part="title">Product updates</span>
</span> </label> <label class="ui-choice" for="notifications-security"> <input class="ui-checkbox" id="notifications-security" name="notifications" type="checkbox" value="security" checked> <span data-ui-part="body"> <span data-ui-part="title">Security notices</span>
</span> </label>
</fieldset>Install
import '@timelessui/components/css/tokens.css'import '@timelessui/components/css/core/choice-groups.css'import '@timelessui/components/css/core/forms.css'import '@timelessui/components/css/themes/atmosphere/tokens.css'import '@timelessui/components/css/themes/atmosphere/forms.css'import '@timelessui/components/css/themes/atmosphere/choice-groups.css'import '@timelessui/components/register/ui-checkbox-group'A register/ import is a side effect: it defines the element as the module evaluates, so it has to run in code the browser loads. To register explicitly instead — to control the timing, or to define into another window — call the function from the matching define/ entry point, which registers nothing on its own:
import { defineCheckboxGroupElement } from '@timelessui/components/define/ui-checkbox-group'defineCheckboxGroupElement()Anatomy
Parts are authored in your own markup and identified by the selector below, so your CSS can target the same anatomy without loading Timeless styles. Required parts must be present for the component to work. Private data-ui-internal-* hooks are written by the runtime and must never be authored.
<ui-checkbox-group>
| Part | Required | Selector | Purpose |
|---|---|---|---|
choice | Yes | input[type='checkbox'] | One native checkbox input. Author checked for the initial state; the group reports every checked value. |
ui-choice-group
| Part | Required | Selector | Purpose |
|---|---|---|---|
description | No | [data-ui-part~='description'] | Group-level help text under the legend. |
error | No | [data-ui-part~='error'] | Group-level validation message. |
ui-choice
| Part | Required | Selector | Purpose |
|---|---|---|---|
body | No | [data-ui-part~='body'] | Wrapper for the title and description beside the control. |
title | No | [data-ui-part~='title'] | The choice label text. |
description | No | [data-ui-part~='description'] | Supporting copy under the choice label. |
Attributes
Every value below is implemented by the stylesheets this component ships. Boolean attributes are presence-based: author the attribute with no value, or omit it.
<ui-checkbox-group>
| Attribute | Values | Default | Description |
|---|---|---|---|
orientation | vertical · horizontal | vertical | Layout and arrow-key axis. |
ui-choice-group
| Attribute | Values | Default | Description |
|---|---|---|---|
data-ui-orientation | vertical · horizontal | vertical | Layout direction of the choices. |
data-ui-density | compact · normal · spacious | normal | Gap between choices. |
ui-choice
| Attribute | Values | Default | Description |
|---|---|---|---|
data-ui-density | compact · normal · spacious | normal | Gap between the control and its label. |
Element API
Attributes above are the authoring surface. These are the DOM properties and events the registered element adds once it upgrades.
<ui-checkbox-group>
| Property | Type | Notes |
|---|---|---|
orientation | 'vertical' | 'horizontal' | Reflects the orientation attribute, documented above. |
| Event | Detail | Description |
|---|---|---|
ui-before-change | CustomEvent<CheckboxGroupChangeDetail> | Cancelable proposal dispatched before the set of checked boxes changes. Call preventDefault() to reject the transition and keep the current value. |
ui-change | CustomEvent<CheckboxGroupChangeDetail> | Dispatched after the set of checked boxes has changed. Bubbles and is composed. |
State
Native attributes, ARIA, and platform pseudo-classes are authoritative. Style state through the selectors below rather than adding your own state classes.
| State | Source | How to express it |
|---|---|---|
invalid | aria | Set aria-invalid="true" on the <fieldset> and describe the error. |
invalid | native | Native :invalid, or aria-invalid="true". |
disabled | native | Native disabled. |
Styling
Root identity: ui-checkbox-group, ui-choice-group, ui-choice, ui-checkbox. Required stylesheets: tokens.css, core/choice-groups.css, core/forms.css, themes/atmosphere/tokens.css, themes/atmosphere/forms.css, themes/atmosphere/choice-groups.css.
This component adds no custom properties of its own. Restyle it through the design tokens or your own CSS.
Design tokens this component reads (26)
These are global Atmosphere tokens. Change them once at the theme level rather than per component.
--ui-accent · --ui-bg-control · --ui-bg-control-muted · --ui-bg-surface · --ui-bg-surface-subtle · --ui-danger · --ui-danger-soft · --ui-disabled-opacity · --ui-duration-fast · --ui-ease-standard · --ui-fg · --ui-fg-muted · --ui-fg-subtle · --ui-focus · --ui-line · --ui-line-strong · --ui-radius-md · --ui-radius-pill · --ui-radius-sm · --ui-shadow-control · --ui-shadow-inset · --ui-space-1 · --ui-space-2 · --ui-space-3 · --ui-space-4 · --ui-space-5
Accessibility
Keep the native elements, roles, and relationships shown in the example. Timeless adds only the state and keyboard coordination the platform does not already provide, and it never supplies your accessible names — those depend on your content.
Follows the Checkbox pattern from the ARIA Authoring Practices Guide.
Every key comes from the native checkboxes: Tab reaches each one, Space toggles the focused box, and each box submits its own value. There is deliberately no roving tabindex and no arrow navigation — a checkbox group is a set of independent controls rather than one composite widget, so each being its own tab stop is the APG treatment. ui-checkbox-group adds only the group role, the orientation, and one change event for the set. A group that should be one tab stop is a [Listbox](/docs/components/listbox/) with multiple.
Before JavaScript runs
The markup above is complete and usable on its own: native controls submit, labels associate, and authored ARIA is already correct. Registration adds state synchronisation, focus management, and keyboard coordination on top of it.
More examples
Open Checkbox Group in StoryLite for variants, controls, and manual testing.