If an element is wrapped by a label, does the label require the “for” attribute?

前端 未结 2 512
夕颜
夕颜 2021-01-18 23:31

Say I have a set of radio s. I\'m not a caveman, so I know I need to associate with those s. I

2条回答
  •  攒了一身酷
    2021-01-19 00:00

    According to the HTML5 spec - "If the for attribute is not specified, but the label element has a labelable element descendant, then the first such descendant in tree order is the label element's labeled control."

    http://www.w3.org/TR/html5/forms.html#category-label

    So basically, no it is not required as long as it is wrapping any of these elements: button, input (if the type attribute is not in the hidden state), keygen, meter, output, progress, select, or textarea

提交回复
热议问题