Create consistent cross-browser and cross-device checkboxes and radios with our completely rewritten checks component.
Browser default checkboxes and radios are replaced with the help of FormCheck
, a series of classes for both input types that improves the layout and behavior of their HTML elements, that provide greater customization and cross browser consistency.
Checkboxes are for selecting one or several options in a list, while radios are for selecting one option from many.
Structurally, our FormCheckInput
s and FormCheckLabel
s are sibling elements as opposed to an FormCheckInput
within a FormCheckLabel
.
This is slightly more verbose as you must specify id
and for
attributes to relate the FormCheckInput
and FormCheckLabel
.
We use the sibling selector (~
) for all our FormCheckInput
states, like :checked
or :disabled
.
When combined with the .form-check-label
class, we can easily style the text for each item based on the FormCheckInput
's state.
Our checks use custom Bootstrap icons to indicate checked or indeterminate states.
Checkboxes can utilize the indeterminate
attributes when manually set.
Add the disabled
attribute and the associated FormCheckLabel
s are automatically styled to match with a lighter color to help indicate the input's state.
Add the disabled
attribute and the associated FormCheckLabel
s are automatically styled to match with a lighter color to help indicate the input's state.
A switch has the markup of a custom checkbox but uses the switch
class to render a toggle switch. Consider using role="switch"
to more accurately convey the nature of the control to assistive technologies that support this role. In older assistive technologies, it will simply be announced as a regular checkbox as a fallback. Switches also support the disabled
attribute.
By default, any number of checkboxes and radios that are immediate sibling will be vertically stacked and appropriately spaced with FormCheck
.
Group checkboxes or radios on the same horizontal row by adding inline
to any FormCheck
.
Put your checkboxes, radios, and switches on the opposite side with the reverse
modifier class.
Omit the wrapping FormCheck
for checkboxes and radios that have no label text.
Remember to still provide some form of accessible name for assistive technologies (for instance, using aria-label
).
Create button-like checkboxes and radio buttons by using .btn
styles rather than .form-check-label
on the FormCheckLabel,
elements.
These toggle buttons can further be grouped in a button group
if needed.
Different variants of .btn
, such at the various outlined styles, are supported.