Checkboxes and radio buttons

Checkboxes

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.




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.


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).

Secondary/outline style

For the secondary style of the checkbox just add the .checkbox-outline class to the .checkbox wrapper.






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
  • It is useful to see all options at the same time
  • The choices needs to be emphasized



Secondary/outline style

For the secondary style of the checkbox just add the .radio-outline class to the .radio wrapper.




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.

Checkboxes



Radio buttons


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.

Inline checkboxes and radios

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