name attribute in a group of radio buttons?name attribute?The name attribute groups radio buttons so that only one button in that group can be selected at a time. This is standard HTML behavior and Bootstrap uses it as well.
form-check and form-check-input classes.Bootstrap 5 requires wrapping the checkbox input in a div with class form-check. The input uses class form-check-input and the label uses form-check-label with a matching for attribute.
<div class="form-check"> <input class="form-check-input" type="radio" name="colorOptions" id="redOption" value="red" checked> <label class="form-check-label" for="redOption">Red</label> </div> <div class="form-check"> <input class="form-check-input" type="radio" name="colorOptions" id="blueOption" value="blue"> <label class="form-check-label" for="blueOption">Blue</label> </div>
type and checked attributes.The code creates two radio buttons with the same name, so only one can be selected. The 'Red' option has the checked attribute, so it is selected by default.
Bootstrap checkboxes have the input and label as siblings inside div.form-check. To style the label when the checkbox is checked, use the adjacent sibling selector + label.form-check-label after the checked input.
Associating label elements with inputs via matching for and id attributes helps screen readers announce the label when the input is focused. This is essential for accessibility.