--- templateEngineOverride: njk layout: layouts/page.njk title: Checkbox description: A control that allows the user to toggle between checked and not checked. toc: - label: Usage id: usage - label: Checked state id: checked-state - label: Invalid state id: invalid-state - label: Examples id: examples children: - label: Basic id: example-basic - label: Description id: example-description - label: Disabled id: example-disabled - label: Group id: example-group - label: Table id: example-table - label: RTL id: example-rtl --- {% from "macros/code_preview.njk" import code_preview %} {% from "macros/code_block.njk" import code_block %} {% set code %}
{% endset %} {{ code_preview("checkbox", code) }}

Usage

Add the input class to your <input type="checkbox"> elements. Pair it with Field and a native <label> for proper layout and labeling.

{% set code %}{% endset %} {{ code_block(code) }}

Checked state

Use native HTML attributes for state. Add checked for an initially checked checkbox, or read and update the element's checked property in JavaScript.

{% set code %}{% endset %} {{ code_block(code) }}

Invalid state

Set aria-invalid="true" on the checkbox and, when using field, set data-invalid="true" on the field wrapper.

{% set code %}

You must accept the terms to continue.

{% endset %} {{ code_preview("checkbox-invalid", code) }}

Examples

Basic

{% set code %}
{% endset %} {{ code_preview("checkbox-basic", code) }}

Description

{% set code %}

By clicking this checkbox, you agree to the terms and conditions.

{% endset %} {{ code_preview("checkbox-description", code) }}

Disabled

{% set code %}
{% endset %} {{ code_preview("checkbox-disabled", code) }}

Group

{% set code %}
Sidebar

Select the items you want to display in the sidebar.

{% endset %} {{ code_preview("checkbox-group", code) }}

Table

{% set code %}
Status Email
Active olivia@example.com
Inactive noah@example.com
{% endset %} {{ code_preview("checkbox-table", code) }}

RTL

Checkbox layout uses document direction and logical spacing. Set dir="rtl" on a parent to render right-to-left.

{% set code %}

يمكنك تغيير هذا الخيار في أي وقت.

{% endset %} {{ code_preview("checkbox-rtl", code) }}