Checkbox <input>
Checkboxes let users select one or more options, or toggle a single setting on or off.
<input><l-form-field>
<label>Subscribe to the newsletter</label>
<input type="checkbox" />
<p class="l-hint">One email a month, unsubscribe anytime.</p>
</l-form-field>l-form-field auto-styles a bare <input type="checkbox"> and wires the accessibility (label, hint, error, aria-*). Standalone, apply .l-checkbox to the input yourself.
For a single setting that takes effect immediately (no Save button), use a switch instead.
Options
Checked
Native checked attribute.
Disabled
Native disabled attribute.
States
Code
<div class="flex flex-col gap-3">
<label class="flex items-center gap-2">
<input
type="checkbox"
class="l-checkbox"
/>
Unchecked
</label>
<label class="flex items-center gap-2">
<input
type="checkbox"
class="l-checkbox"
checked
/>
Checked
</label>
<label class="flex items-center gap-2">
<input
type="checkbox"
class="l-checkbox"
id="demo-indeterminate"
/>
Indeterminate
</label>
<label class="flex items-center gap-2">
<input
type="checkbox"
class="l-checkbox"
disabled
/>
Disabled
</label>
<label class="flex items-center gap-2">
<input
type="checkbox"
class="l-checkbox"
checked
disabled
/>
Disabled checked
</label>
<label class="flex items-center gap-2">
<input
type="checkbox"
class="l-checkbox"
aria-invalid="true"
/>
Invalid
</label>
<label class="flex items-center gap-2">
<input
type="checkbox"
class="l-checkbox"
checked
aria-invalid="true"
/>
Invalid checked
</label>
</div>Invalid
Styled via :user-invalid (after interaction) or by setting aria-invalid="true". Inside l-form-field this is managed for you.
Size & accent
Override --size for the box and --accent for the checked fill.
Code
<div class="flex items-center gap-4">
<input
type="checkbox"
class="l-checkbox"
checked
/>
<input
type="checkbox"
class="l-checkbox [--size:1.5rem]"
checked
/>
<input
type="checkbox"
class="l-checkbox [--size:2rem] [--accent:var(--l-color-gray-900)]"
checked
/>
</div>Examples
With a hint
.l-hint adds always-visible helper text, linked to the control via aria-describedby.
One email a month, unsubscribe anytime.
Code
<l-form-field>
<label>Subscribe to the newsletter</label>
<input type="checkbox" />
<p class="l-hint">One email a month, unsubscribe anytime.</p>
</l-form-field>With an error
.l-error holds the validation message — hidden until the field is invalid, then revealed with aria-invalid and announced (role="alert"). invalid on the field forces the state here for the preview.
Read them before checking this box.
You must accept the terms to continue.
Code
<l-form-field invalid>
<label>I accept the terms and conditions</label>
<input
type="checkbox"
required
/>
<p class="l-hint">Read them before checking this box.</p>
<p class="l-error">You must accept the terms to continue.</p>
</l-form-field>Accessibility
Criteria
- Role
Uses native
<input type=checkbox>— built-incheckboxsemantics andchecked/mixedstatesWCAG4.1.2RGAA11.1- Target size
The label is part of the click target; keep the interactive area at least 24×24px
WCAG2.5.8
Keyboard interactions
API reference
Importing
@import 'luxen-ui/css/checkbox';Attributes & Properties
checkedAttribute- Whether the checkbox is checked.
disabledAttribute- Disables the checkbox.
requiredAttribute- Marks the checkbox as required for form submission.
indeterminateAttribute- Indeterminate state (DOM property
el.indeterminate = true; renders a dash). Typically the parent of a group. aria-invalidAttribute- Set to
trueto force the invalid style (otherwise applied via:user-invalid).l-form-fieldmanages this automatically.
CSS classes
.l-checkboxClass- Base checkbox style, applied to
<input type="checkbox">. Insidel-form-fielda bare checkbox is auto-styled, so the class is optional there.
CSS custom properties
--sizedefault:1.25emCustom property- Box size.
--accentdefault:var(--l-form-control-activated-color)Custom property- Checked/indeterminate fill color.
--checkmarkCustom property- Checkmark icon as a
url(). Override to swap the SVG (color is baked into the image).