Checkboxes let the user toggle a single option for switching a feature on or off. Each checkbox has a label to the right with the name of the option. Related checkboxes can be grouped with a common label to the left.
Use when:
The user has to set an option that is either true or false
Changing state may need some additional steps (OK, Save, or similar)
The disabled style will be applyed for any of this: add .disabled class to your .radio, .checkbox or <fieldset>, or disabled attribute or disabled class on the input.
<divclass="checkbox"><inputtype="checkbox"id="checkbox-example-1"><labelfor="checkbox-example-1">Option one is this</label></div><br><divclass="checkbox mb-24"><inputtype="checkbox"id="checkbox-outline-example-4"checked="checked"><labelfor="checkbox-outline-example-4">Option two - checked</label></div><br><divclass="checkbox"><inputclass="disabled"type="checkbox"tabindex="-1"aria-disabled="true"id="checkbox-example-2"><labelfor="checkbox-example-2">Option three - disabled</label></div><br><divclass="checkbox disabled"><inputdisabled="disabled"type="checkbox"id="checkbox-example-3"checked="checked"><labelfor="checkbox-example-3">Option four - checked and disabled</label></div>
Indeterminate / mixed state
The third checkboxes state, when is between checked and unchecked, can be added by adding .mixed class to the wrapper that contain the .checkbox class.
<divclass="checkbox mixed"><inputtype="checkbox"id="mixed-checkbox-example"><labelfor="mixed-checkbox-example"aria-checked="mixed">Indeterminate option with <code>.mixed</code> class</label></div><br><divclass="checkbox mixed"><inputdisabledtype="checkbox"id="mixed-checkbox-example-2"><labelfor="mixed-checkbox-example-2"aria-checked="mixed">Indeterminate option and disabled</label></div>
Or you can utilize the :indeterminate pseudo class (MDN Web Docs or caniuse) when manually set via JavaScript (there is no available HTML attribute for specifying it).
<divclass="checkbox checkbox-outline"><inputtype="checkbox"id="checkbox-outline-example-1"><labelfor="checkbox-outline-example-1">Option one - unchecked</label></div><br><divclass="checkbox checkbox-outline mixed"><inputtype="checkbox"id="checkbox-outline-example-2"><labelfor="checkbox-outline-example-2">Option two - mixed</label></div><br><divclass="checkbox checkbox-outline mb-32"><inputtype="checkbox"id="checkbox-outline-example-3"checked="checked"><labelfor="checkbox-outline-example-3">Option three - checked</label></div><br><divclass="checkbox checkbox-outline disabled"><inputdisabled="disabled"type="checkbox"id="checkbox-outline-example-4"><labelfor="checkbox-outline-example-4">Option four - unchecked and disabled</label></div><br><divclass="checkbox checkbox-outline mixed disabled"><inputtype="checkbox"id="checkbox-outline-example-5"tabindex="-1"><labelfor="checkbox-outline-example-5">Option five - mixed and disabled</label></div><br><divclass="checkbox checkbox-outline disabled"><inputdisabledtype="checkbox"id="checkbox-outline-example-6"checked="checked"><labelfor="checkbox-outline-example-6">Option six - checked and disabled</label></div>
Radio buttons
Radio buttons let the user choose one option out of two or more choices. Each radio button has a label to the right with the name of the option. Related radio buttons should be grouped with a common label unless the options are self-explanatory.
Use when:
The user needs to choose one value out of a predefined set of options
The user benefits from getting guidance on what to choose
<divclass="radio"><inputname="optionsRadios"id="optionsRadios1"value="option1"type="radio"><labelfor="optionsRadios1">Option one selecting it will deselect option two</label></div><br><divclass="radio mb-32"><inputname="optionsRadios"id="optionsRadios2"value="option2"checked="checked"type="radio"><labelfor="optionsRadios2">Option two is checked</label></div><br><divclass="radio disabled"><inputname="optionsRadios"id="optionsRadios3"value="option3"disabled="disabled"type="radio"><labelfor="optionsRadios3">Option three is disabled</label></div><br><divclass="radio disabled"><inputname="optionsRadiosa"id="optionsRadios4"value="option4"disabledtype="radio"checked><labelfor="optionsRadios4">Option four is checked and disabled</label></div>
Secondary/outline style
For the secondary style of the checkbox just add the .radio-outline class to the .radio wrapper.
<divclass="example-box example-box-border-only bg-default"><divclass="radio radio-outline"><inputname="optionsRadiosOutline"id="optionsRadiosOutline1"value="option1"type="radio"><labelfor="optionsRadiosOutline1">Option one will deselect option two</label></div><br><divclass="radio radio-outline mb-32"><inputname="optionsRadiosOutline"id="optionsRadiosOutline2"value="option2"checked="checked"type="radio"><labelfor="optionsRadiosOutline2">Option one is checked</label></div><br><divclass="radio radio-outline disabled"><inputname="optionsRadiosOutline"id="optionsRadiosOutline3"value="option3"disabled="disabled"type="radio"><labelfor="optionsRadiosOutline3">Option three is disabled</label></div><br><divclass="radio radio-outline disabled"><inputname="optionsRadiosOutlineA"id="optionsRadiosOutline4"value="option4"disabled="disabled"type="radio"checked="checked"><labelfor="optionsRadiosOutline4">Option four is checked and disabled</label></div></div>
Disabled as readonly
To present a checkbox or radio button in a non-interactive state that preserves its current value, apply the disabled attribute to the input. You can optionally use the .disabled class on the wrapper, for example when disabling a group or to reinforce the visual disabled state.
<divclass="checkbox disabled"><inputtype="checkbox"id="checkbox-disabled-readonly-example-1"disabled><labelfor="checkbox-disabled-readonly-example-1">Option one - unchecked</label></div><br><divclass="checkbox disabled"><inputtype="checkbox"id="checkbox-disabled-readonly-example-2"disabledchecked><labelfor="checkbox-disabled-readonly-example-2">Option two - checked</label></div><br><divclass="checkbox mixed disabled"><inputtype="checkbox"id="checkbox-disabled-readonly-example-3"disabled><labelfor="checkbox-disabled-readonly-example-3">Option three - mixed</label></div>
<divclass="radio disabled"><inputtype="radio"id="radio-disabled-readonly-example-1"disabled><labelfor="radio-disabled-readonly-example-1">Option one - unchecked</label></div><br><divclass="radio disabled"><inputtype="radio"id="radio-disabled-readonly-example-2"disabledchecked><labelfor="radio-disabled-readonly-example-2">Option two - checked</label></div>
Why not use the readonly attribute?
The HTML readonly attribute has no effect on checkboxes or radio buttons. It is only supported on text-based inputs such as <input type="text"> and <textarea>. Browsers silently ignore readonly on checkboxes and radio buttons, meaning users can still change the value despite the attribute being present.
Use the disabled attribute instead to prevent user interaction. If the value must be submitted with the form, consider adding a hidden <input> that carries the value alongside the disabled control.
<formaction=""class="mb-32"><divclass="checkbox mr-24"><inputtype="checkbox"id="inlineCheckbox1"value="option1"><labelfor="inlineCheckbox1">Inline checkbox 1</label></div><divclass="checkbox mr-24"><inputtype="checkbox"id="inlineCheckbox2"value="option2"><labelfor="inlineCheckbox2">Inline checkbox 2</label></div><divclass="checkbox mr-24"><inputtype="checkbox"id="inlineCheckbox3"value="option3"><labelfor="inlineCheckbox3">Inline checkbox 3</label></div></form><formaction=""class=""><divclass="radio mr-24"><inputtype="radio"id="inlineRadio1"value="option1"name="inlineRadio"><labelfor="inlineRadio1">Inline radio 1</label></div><divclass="radio mr-24"><inputtype="radio"id="inlineRadio2"value="option2"name="inlineRadio"><labelfor="inlineRadio2">Inline radio 2</label></div><divclass="radio mr-24"><inputtype="radio"id="inlineRadio3"value="option3"name="inlineRadio"><labelfor="inlineRadio3">Inline radio 3</label></div></form>
Checkboxes and radios in a block/list format
The vertical/list format of the checkboxes and radio boxes can be achieved by using the clasic </br> tag, a different aproch is by using an unordered list element, or flex boxes helper classes on a wrapper for the items.
In the next example is presented the flexbox helper classes approach, with a flex-direction column and align-items value as flex-start