What is aria-label and how should I use it?

前端 未结 6 2025
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 16:52

A few hours ago I read about the aria-label attribute, which:

Defines a string value that labels the current element.

But in my

6条回答
  •  [愿得一人]
    2020-11-30 17:45

    It's an attribute designed to help assistive technology (e.g. screen readers) attach a label to an otherwise anonymous HTML element.

    So there's the element:

    
    
    

    The explicitly tells the user to type their name into the input box where id="fmUserName".

    aria-label does much the same thing, but it's for those cases where it isn't practical or desirable to have a label on screen. Take the MDN example:

    `
    

    Most people would be able to infer visually that this button will close the dialog. A blind person using assistive technology might just hear "X" read aloud, which doesn't mean much without the visual clues. aria-label explicitly tells them what the button will do.

提交回复
热议问题