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

后端 未结 8 1112
一生所求
一生所求 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:07

    The 'label for' syntax means the label you have created is intended to be a label for the input with id 'inp'. If you click this label in most browsers the cursor focus will land on the 'inp' input element. It's a nice little way of linking a label with its corresponding form control.

    I'm not aware of compatibility issues, or any around performance. To me it seems syntactically sound, and as far as I'm aware the CSS spec claims that both are valid.

提交回复
热议问题