Performance: Checkboxes and radios
This affects page interactivity speed and rendering performance when many checkboxes or radio buttons are used.
<fieldset class="form-group"> <legend>Select options</legend> <div class="form-check"> <input class="form-check-input" type="checkbox" id="check1"> <label class="form-check-label" for="check1">Option 1</label> </div> <!-- Render only visible or paginated options --> </fieldset>
<div class="form-check"> <input class="form-check-input" type="checkbox" id="check1"> <label class="form-check-label" for="check1">Option 1</label> </div> <!-- repeated 1000 times -->
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| 1000 individual checkboxes rendered at once | High DOM nodes (1000+) | 1000+ reflows | High paint cost | [X] Bad |
| Grouped checkboxes with pagination or lazy rendering | Low DOM nodes (visible only) | Few reflows | Low paint cost | [OK] Good |
form-check-input on the input and form-check-label on the label.for attribute must match input's id.<div class='form-check'> <input class='form-check-input' type='radio' name='color' id='red' checked> <label class='form-check-label' for='red'>Red</label> </div> <div class='form-check'> <input class='form-check-input' type='radio' name='color' id='blue'> <label class='form-check-label' for='blue'>Blue</label> </div>
checked attribute, so it is selected initially.<div class='form-check'> <input class='form-check-input' type='checkbox' id='agree'> <label class='form-check-label' id='agree'>I agree</label> </div>
for attribute matching the input's id for accessibility and clicking.id='agree' instead of for='agree'.form-check-input, labels must have form-check-label, and labels must use for matching input id.Pass the test and this pattern moves unknown