Can an input field have two labels?

后端 未结 3 1339
一整个雨季
一整个雨季 2020-12-08 08:56

Mary had a little form, and its fields where labeled just so.
Whenever an error crept in, confusion it would sow.

I\'ve got a label for each input field

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 09:29

    The HTML is legal, and it works (clicking on any of the labels will transfer focus to the field in question).

    It's a little trickier to do right for accessibility reasons.

    It's not a "common" approach, and because of that at least one common screen reader (I tested with NVDA) only reads the first label when you shift focus into the field -- it ignores any additional labels for the same field.

    So if your error message is at the top of the page, a blind or low-vision user tabbing through the fields will hear just the error message when landing on the field in question, not the "real" label next to it.

    Hence -- if you phrase the error message properly, that might be a good thing (certainly better than just highlight the non-validating field in red!).

提交回复
热议问题