3 ms·
I generally wrap my radios inside of the label for this reason. Is there a reason not to do that?
by christophilus 2y ago
I generally wrap my radios inside of the label for this reason. Is there a reason not to do that?
- marcosdumay 2y agoAFAIK, the only reason to use the label's `for` is when you want to place it in a different place from the widget.
- emsimot 2y agoIt also helps with accessibility, screen readers etc
- marcosdumay 2y agoNot compared to including the widget inside the label.
- jay-barronville 2y ago> I generally wrap my radios inside of the label for this reason. Is there a reason not to do that? Actually, I think this is the best way to deal with all inputs that have labels—a small number of issues and edge cases (such as the one described in the article) just disappear. It’s also valid hierarchy-wise.
- parasti 2y agoYou can't style the label based on input state if you do that. If you instead order them like input + label, then you can style the label with selectors like input:checked + label.
- agos 2y agoyou can, with the power of :has! label:has(input:checked) { background-color: orange; }