Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Bootstrap5 Checkboxes and Radio Buttons

Bootstrap5 Checkboxes and Radio Buttons

If you want users to select any number of options from a preset list, use checkboxes:

Example

<div class="form-check">
<input class="form-check-input" type="checkbox" id="check1" name="option1" value="something" checked>
<label class="form-check-label">

Option 1

label

div

Try it »

Checkboxes use class="form-check" to ensure the label and checkbox have appropriate margins.

Add the .form-check-label class to the label element, and add the .form-check-input class inside the .form-check container to set the checkbox style.

The checked attribute is used to set the option selected by default.

Radio buttons

If you want users to select one option from a preset list, use radio buttons:

Example

<div class="form-check">
<input type="radio" class="form-check-input" id="radio1" name="optradio" value="option1" checked>

Option 1

<label class="form-check-label" for="radio1" label div>
<div class="form-check">
<input type="radio" class="form-check-input" id="radio2" name="optradio" value="option2">

Option 2

<label class="form-check-label" for="radio2" label div>
<div class="form-check">
<input type="radio" class="form-check-input" disabled>

Option 3

<label class="form-check-label" label div>

Try it »

Toggle Switch

If you want to turn a checkbox into a toggle switch, you can use the .form-check .form-switch class inside the container:

Example

<div class=">

form-check form-switch

"

<input class="form-check-input" type="checkbox" id="mySwitch" name="darkmode" value="yes" checked>
<label class="form-check-label" for="mySwitch">

Dark Mode

label

div

Try it »