Checkbox
Material Design checkboxes allow users to select one or more items from a set. They can appear as unchecked, checked, or indeterminate.
Theme Variables
You can customize the checkbox sizes by overriding its CSS variables.
css
:root {
--checkbox-target: calc(var(--spacing) * 12); /* 48px touch target */
--checkbox-size: calc(var(--spacing) * 4.5); /* 18px visual size */
}These variables define the overall clickable touch target area and the inner visual size of the checkbox square.
Composed Utilities
The primary out-of-the-box utility is checkbox-input, designed to be applied directly to a native <input type="checkbox"> element.
html
<!-- Native Checkbox Input -->
<input type="checkbox" class="checkbox-input" />
<!-- Checked State -->
<input type="checkbox" class="checkbox-input" checked />
<!-- Disabled State -->
<input type="checkbox" class="checkbox-input" disabled />checkbox-input: A highly composed utility. It builds uponcheckbox-baseand applies thestate-layerutility to expand the clickable touch target to 48x48 pixels via the::beforepseudo-element. It automatically injects the checkmark or indeterminate SVG icons using CSSmask-imageon the::afterpseudo-element (reusingcurrentColor). It natively responds to:checked,:indeterminate,[aria-checked='true'],[aria-checked='mixed'], and:disabled.
Composing Utilities
For custom wrapper-based implementations where the native input might be visually hidden, you can use the modular utilities.
html
<label class="checkbox-container">
<input type="checkbox" class="sr-only peer" />
<div class="checkbox peer-checked:checkbox-checked">
<svg class="checkbox-icon peer-checked:checkbox-checked-icon">...</svg>
</div>
</label>checkbox-container: A 48x48inline-flexwrapper that centers its content and applies hover background transitions. It also handles focus rings for the internal checkbox elements.checkbox: Appliescheckbox-basealong with built-inbox-shadowfocus rings when:focus-visible.checkbox-base: Renders the 18x18 checkbox square with a 2px border and handles transition properties for background, border, and color.checkbox-icon: A sizing and transition utility for an SVG icon placed inside the checkbox. Initializes withopacity: 0.
State Utilities
checkbox-checked: Applies the primary background and border color for the checked state.checkbox-indeterminate: Applies the primary background and border color for the mixed state.checkbox-checked-icon,checkbox-indeterminate-icon: Setsopacity: 1on the icon to reveal it.checkbox-disabled: Lowers opacity (0.38), sets the disabled border color, and removes pointer events.checkbox-disabled-checked: Specific background and color resets for a checkbox that is both disabled and checked.checkbox-hover: Applies an 8% color-mix background on hover.