Performance: Select menus
Select menus impact page load speed and interaction responsiveness, especially when styled or enhanced with JavaScript.
<select class="form-select" aria-label="Choose option"> <!-- fewer options or options loaded on demand --> </select>
<select class="custom-select" style="width: 100%;" onchange="heavyJsFunction()"> <!-- 100+ <option> elements --> </select>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Native select with few options | Minimal DOM nodes | 1 reflow on open/close | Low paint cost | [OK] Good |
| Custom select with 100+ options and heavy JS | Many DOM nodes | Multiple reflows on interaction | High paint cost | [X] Bad |
form-select class in Bootstrap?form-select class is specifically designed to style <select> elements, giving them a consistent Bootstrap appearance.form-select is not used for those.value or selected attributes?form-select.<option> tags without values are valid.<select class="form-select" aria-label="Favorite color"> <option selected>Choose color</option> <option value="red">Red</option> <option value="green">Green</option> <option value="blue">Blue</option> </select>
form-select class applies Bootstrap styling to the dropdown. The aria-label improves accessibility but does not affect appearance.selected attribute, so it appears as the default visible text: "Choose color".<select class="form-select"> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> </select> <label for="select">Numbers</label>
label uses for="select" but the select element has no id="select", so the label is not linked properly.id and for attributes, and usually placed before or after but linked correctly.multiple attribute allows selecting multiple options. The class form-select is correct for Bootstrap styling.for="fruits" matching the select's id="fruits". The aria-label describes the select for screen readers, improving accessibility.Pass the test and this pattern moves unknown