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

后端 未结 8 1139
一生所求
一生所求 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.

提交回复
热议问题