4 ms·
> <input type="radio" name="fruit" id="banana" /><label for="banana">Banana</label> Slightly pedantic, but it's even easier than that if you don't have any ele
by joshuahedlund 13y ago
> <input type="radio" name="fruit" id="banana" /><label for="banana">Banana</label>
Slightly pedantic, but it's even easier than that if you don't have any elements separating them - you don't even need the id:
> <label><input type="radio" name="fruit" /> Banana</label>
This adds convenience on desktop, but it's really annoying not to have it on smaller mobile screens.
- Cyranix 13y agoIt's also compatible with assistive technology (though be sure to note the edge cases): http://www.html5accessibility.com/tests/form-labels.html http://www.html5accessibility.com/tests/form-labels.html (based on discussion 6 months ago: https://news.ycombinator.com/item?id=4890631 https://news.ycombinator.com/item?id=4890631)
- pwg 13y agoThe first version became popular because for by far too long, the IE's failed to properly handle the second, nested, version. The textual label would stubbornly refuse to click the input unless the id= and for= attributes were applied.