Is it better to wrap the label tag around a form item or use the “for” attribute in HTML?

后端 未结 8 1095
一生所求
一生所求 2020-12-02 16:26

I know that you can use both but is it better to use one over the other? If so, why?

Example of \"for\" attribute:



        
相关标签:
8条回答
  • 2020-12-02 17:21

    The relationship is more explicitly defined when using the for syntax, although I believe most browsers implement the same behaviour for both.

    A matter of preference, I think. Personally I would use the for syntax as I think it makes more semantical sense than for the input element to be a part of its label element.

    0 讨论(0)
  • 2020-12-02 17:24

    according to http://www.w3.org/TR/2008/WD-WCAG20-TECHS-20080430/H44.html

    some assistive technologies do not correctly handle implicit labels

    So when you wrap, you may also want to provide the "for" attribute to the label element.

    0 讨论(0)
提交回复
热议问题