Performance: Select dropdown
This affects page load speed and interaction responsiveness because select dropdowns involve rendering native UI components and can trigger layout recalculations when opened.
<label for="select-example">Choose an option:</label> <select id="select-example" name="options"> <option value="1">Option 1</option> <option value="2">Option 2</option> <option value="3">Option 3</option> </select>
<div class="custom-dropdown"> <div class="selected">Choose an option</div> <ul class="options"> <li>Option 1</li> <li>Option 2</li> <li>Option 3</li> </ul> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Native <select> | Minimal nodes (1 select + options) | 1 on load, 1 on open | Low paint cost | [OK] Good |
| Custom dropdown with divs and lists | Many nodes (divs, ul, li) | Multiple on open/close | High paint cost | [X] Bad |
<select> tag do in HTML?<select> tag<select> tag is designed to create a dropdown list where users can pick one option from many.<input> create text boxes, <button> creates buttons, and <p> creates paragraphs, so they do not create dropdowns.<option> tag is used inside <select> to list choices.<select> is for the dropdown container, <input> and <button> are unrelated to dropdown options.<label for="fruits">Choose a fruit:</label> <select id="fruits" name="fruits"> <option value="apple">Apple</option> <option value="banana">Banana</option> <option value="cherry">Cherry</option> </select>
<label> is linked to the <select> by the 'for' and 'id' attributes, showing 'Choose a fruit:' as the label.<select> content<select> contains three <option> tags: Apple, Banana, and Cherry, which appear as choices in a dropdown.<select name="colors"> <option>Red</option> <option value="green">Green</option> <option value="blue">Blue </select>
<option> for Blue is missing its closing </option> tag, which is required for valid HTML.name attribute is valid on <select>, options can have value attributes, and multiple options are allowed.<label for="country">Country:</label>
<select id="country" name="country">
<option value="" disabled selected>Select a country</option>
<option value="usa">USA</option>
<option value="canada">Canada</option>
<option value="mexico">Mexico</option>
</select> uses <label for="country"> and <select id="country">, linking label and dropdown for accessibility.disabled selected attributes, so it shows as default but cannot be chosen.Pass the test and this pattern moves unknown