TExcelTAD
Home › Bootstrap › BS5 Checks & Radios

Bootstrap 5 Checks and Radios

Checkboxes, radio buttons and switches all share one structure in Bootstrap: a wrapper .form-check, the input .form-check-input and its label .form-check-label. Bootstrap replaces the browser's default look with a consistent, theme-coloured one.

Control Use when
Checkbox Each option is independent — pick any number
Radio Options are mutually exclusive — pick exactly one
Switch An on/off setting that takes effect immediately

Checkboxes

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <p class="fw-semibold mb-1">Toppings</p>
  <div class="form-check">
    <input class="form-check-input" type="checkbox" value="cheese" id="cheese" checked>
    <label class="form-check-label" for="cheese">🧀 Cheese</label>
  </div>
  <div class="form-check">
    <input class="form-check-input" type="checkbox" value="mushroom" id="mushroom">
    <label class="form-check-label" for="mushroom">🍄 Mushrooms</label>
  </div>
  <div class="form-check">
    <input class="form-check-input" type="checkbox" value="pineapple" id="pineapple" disabled>
    <label class="form-check-label" for="pineapple">🍍 Pineapple (sold out)</label>
  </div>
  <div class="form-check">
    <input class="form-check-input" type="checkbox" id="all">
    <label class="form-check-label" for="all">Indeterminate (set by JS)</label>
  </div>
  <script>
    document.getElementById('all').indeterminate = true;
    document.addEventListener('change', (e) => console.log(e.target.value || e.target.id, e.target.checked));
  </script>
</body>
</html>

The indeterminate state ("partly selected") can only be set from JavaScript; it's typically used for a "select all" box when only some items are checked.

Radios

Radios with the same name form a group — selecting one deselects the others.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <fieldset>
    <legend class="fs-6 fw-semibold">Delivery</legend>
    <div class="form-check">
      <input class="form-check-input" type="radio" name="delivery" id="std" value="standard" checked>
      <label class="form-check-label" for="std">Standard (3–5 days) — free</label>
    </div>
    <div class="form-check">
      <input class="form-check-input" type="radio" name="delivery" id="exp" value="express">
      <label class="form-check-label" for="exp">Express (1 day) — $9</label>
    </div>
  </fieldset>
  <fieldset class="mt-3">
    <legend class="fs-6 fw-semibold">Rating (inline)</legend>
    <div class="form-check form-check-inline">
      <input class="form-check-input" type="radio" name="rate" id="r1" value="1"><label class="form-check-label" for="r1">1</label>
    </div>
    <div class="form-check form-check-inline">
      <input class="form-check-input" type="radio" name="rate" id="r2" value="2"><label class="form-check-label" for="r2">2</label>
    </div>
    <div class="form-check form-check-inline">
      <input class="form-check-input" type="radio" name="rate" id="r3" value="3"><label class="form-check-label" for="r3">3</label>
    </div>
  </fieldset>
  <script>
    document.addEventListener('change', (e) => console.log(e.target.name, '=', e.target.value));
  </script>
</body>
</html>

.form-check-inline places checks or radios side by side. Wrapping a group in a <fieldset> with a <legend> tells screen readers what the group is about.

Switches

Add .form-switch to the wrapper (and role="switch" to the input) to turn a checkbox into a toggle switch.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <div class="form-check form-switch">
    <input class="form-check-input" type="checkbox" role="switch" id="wifi" checked>
    <label class="form-check-label" for="wifi">Wi-Fi</label>
  </div>
  <div class="form-check form-switch">
    <input class="form-check-input" type="checkbox" role="switch" id="bt">
    <label class="form-check-label" for="bt">Bluetooth</label>
  </div>
  <div class="form-check form-switch form-check-reverse">
    <input class="form-check-input" type="checkbox" role="switch" id="air">
    <label class="form-check-label" for="air">Reversed (label first)</label>
  </div>
  <p class="mt-2 small" id="status"></p>
  <script>
    const update = () => {
      document.getElementById('status').textContent =
        `Wi-Fi ${document.getElementById('wifi').checked ? 'on' : 'off'}, Bluetooth ${document.getElementById('bt').checked ? 'on' : 'off'}`;
    };
    document.addEventListener('change', update);
    update();
  </script>
</body>
</html>

Toggle buttons

The .btn-check class hides the input and lets you style the label as a button, for a more visual choice (covered in detail in the Button Groups lesson).

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <input type="checkbox" class="btn-check" id="news" autocomplete="off">
  <label class="btn btn-outline-primary" for="news">📰 Newsletter</label>
  <input type="radio" class="btn-check" name="plan" id="monthly" autocomplete="off" checked>
  <label class="btn btn-outline-success" for="monthly">Monthly</label>
  <input type="radio" class="btn-check" name="plan" id="yearly" autocomplete="off">
  <label class="btn btn-outline-success" for="yearly">Yearly</label>
</body>
</html>

Class reference

Class Purpose
.form-check Wrapper for one check/radio + label
.form-check-input The checkbox or radio
.form-check-label Its label
.form-check-inline Place side by side
.form-switch Render a checkbox as a switch
.form-check-reverse Put the input on the right
.btn-check Hidden input for button-style toggles

Tip: For a checkbox without a visible label (e.g. in a table row), leave out the .form-check wrapper, use the input alone with .form-check-input, and give it an aria-label so screen readers still know what it does.

Test yourself

What makes several radio buttons belong to the same group?

  1. The same id
  2. The same name attribute
  3. The same .form-check wrapper
  4. The same value

Which wrapper class turns a checkbox into a toggle switch?

  1. .form-toggle
  2. .form-switch
  3. .switch
  4. .form-check-switch

How can a checkbox be put in the indeterminate state?

  1. indeterminate attribute in HTML
  2. Only with JavaScript: input.indeterminate = true
  3. .form-check-indeterminate class
  4. checked="half"