What's the “for” for in a label tag?

后端 未结 6 2013
臣服心动
臣服心动 2021-01-31 07:10

Just ran across a for parameter in an HTML label tag:


*         


        
6条回答
  •  星月不相逢
    2021-01-31 07:39

    From w3schools.org:

    The tag defines a label for an input element.

    The label element does not render as anything special for the user. However, it provides a usability improvement for mouse users, because if the user clicks on the text within the label element, it toggles the control.

    The for attribute of the tag should be equal to the id attribute of the related element to bind them together.

    HTH!

    adding my $.02 as an Accessibility SME - as well as usability, the LABEL also associates the input field with the correct label so persons using screen readers will know what the field is for.

提交回复
热议问题