Checkboxes and radio buttons let users pick options on a form. They help collect choices easily.
Checkboxes and radios in Bootsrap
<div class="form-check"> <input class="form-check-input" type="checkbox" value="" id="flexCheckDefault"> <label class="form-check-label" for="flexCheckDefault"> Default checkbox </label> </div> <div class="form-check"> <input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="option1" checked> <label class="form-check-label" for="exampleRadios1"> First radio </label> </div>
Use form-check class to wrap each checkbox or radio for proper spacing.
Use form-check-input on the input and form-check-label on the label for Bootstrap styling.
for and id.<div class="form-check"> <input class="form-check-input" type="checkbox" value="" id="check1"> <label class="form-check-label" for="check1"> Option 1 </label> </div>
<div class="form-check"> <input class="form-check-input" type="radio" name="group1" id="radio1" value="1" checked> <label class="form-check-label" for="radio1"> Radio 1 </label> </div> <div class="form-check"> <input class="form-check-input" type="radio" name="group1" id="radio2" value="2"> <label class="form-check-label" for="radio2"> Radio 2 </label> </div>
form-switch.<div class="form-check form-switch"> <input class="form-check-input" type="checkbox" id="flexSwitchCheckDefault"> <label class="form-check-label" for="flexSwitchCheckDefault">Toggle switch</label> </div>
This page shows a form with checkboxes and radio buttons styled by Bootstrap. Users can pick multiple fruits with checkboxes and one fruit with radio buttons.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap Checkboxes and Radios</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <main class="container py-4"> <h1>Choose your options</h1> <form> <section> <h2>Checkboxes</h2> <div class="form-check"> <input class="form-check-input" type="checkbox" value="apple" id="checkApple"> <label class="form-check-label" for="checkApple">Apple</label> </div> <div class="form-check"> <input class="form-check-input" type="checkbox" value="banana" id="checkBanana"> <label class="form-check-label" for="checkBanana">Banana</label> </div> </section> <section class="mt-4"> <h2>Radio buttons</h2> <div class="form-check"> <input class="form-check-input" type="radio" name="fruit" id="radioOrange" value="orange" checked> <label class="form-check-label" for="radioOrange">Orange</label> </div> <div class="form-check"> <input class="form-check-input" type="radio" name="fruit" id="radioGrape" value="grape"> <label class="form-check-label" for="radioGrape">Grape</label> </div> </section> <button type="submit" class="btn btn-primary mt-3">Submit</button> </form> </main> </body> </html>
Always link label to input using matching for and id for better accessibility.
Use the same name attribute for radio buttons in a group to allow only one selection.
Bootstrap's form-check classes handle spacing and alignment automatically.
Checkboxes let users select multiple options; radios let users select one.
Bootstrap styles checkboxes and radios with form-check, form-check-input, and form-check-label classes.
Always connect labels to inputs for easy clicking and accessibility.