Let’s take one interactive feature apart so the markup and behavior make sense separately.
What You Need to Know
The new customizable-select pattern can place a button inside select as its first child in supporting browsers. Standard selects are a safer fallback where this structure is not implemented.
Try the Example
Take a look at the example. We’ll explain the important lines right below it.
<label for="pet">Choose a pet</label>
<select id="pet" name="pet">
<button><selectedcontent></selectedcontent></button>
<option value="cat">Cat</option>
<option value="dog">Dog</option>
</select>
Let’s Read the Code
- <label>: The label tells people what the input is for. A matching for/id pair makes the label clickable.
- <select>: The select lets someone choose an item from a list.
- for: For connects a label or output with a control by ID.
- id: An id uniquely identifies an element on this page.
Read the named elements and attributes together. They explain how the browser connects this feature to the rest of the page.
What Happens in the Browser?
This feature has limited or experimental browser support. Check your target browsers before using it for something essential.
Do not depend on one browser. Some advanced HTML features are still being adopted. Check support before you build essential navigation or forms with them, and keep a simpler version that people can use if the advanced feature is unavailable.
Your Turn
Try a matching value and a nonmatching one. Can you explain exactly which character fails the pattern?
Common Beginner Mistakes
- Writing a pattern that rejects valid values because it was not tested with realistic examples.
- This feature has limited or experimental browser support. Keep a standard HTML fallback, and check compatibility before using it in a public site.
Key Takeaways
- The new customizable-select pattern can place a button inside select as its first child in supporting browsers.
- <label>: The label tells people what the input is for. A matching for/id pair makes the label clickable.
- This lesson explains an emerging feature; it is not a promise that the feature works in every browser. Keep a usable fallback.