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

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

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


*         


        
6条回答
  •  你的背包
    2021-01-31 07:47

    The "for" attribute is a necessary element for the accessibility of your form. Do not omit it. For someone using a screen reader (SR) to have a web page announced to them, the "for" attribute relates the control to the label. Typically a SR user will tab through a form, from one control (which is a focusable element for the SR) to the next. Without the "for" attribute, the SR user will have to change modes on the SR and probe around the form to try and determine which control matches which label, which can be time-consuming and confusing. The "for" attribute can also be useful for assistive technology relating to motor issues.

    WebAIM.org has a great page explaining the accessibility ramifications of "for": http://webaim.org/techniques/forms/controls

提交回复
热议问题