Alt or title attribute for i tag

前端 未结 5 709
清酒与你
清酒与你 2021-01-30 19:18

I use font-awesome and display their fonts like that:


This will display a nice little lock symbol. For

5条回答
  •  盖世英雄少女心
    2021-01-30 19:56

    With the advance of WAI-ARIA, when using font icons, you probably should use a combination of the following to improve accessibility:

    • The role presentation to remove implicit native role semantics of the element. This is especially important if you (ab)use an element with a native semantic to provide icons, as this is the case in your example using the i element (which, according to the specs, "represents a span of text in an alternate voice or mood [...]").
    • An aria-label to provide a string value that labels the element -or- a native HTML title attribute if you are OK with the browser displaying a tooltip when hovered.
    • An aria-hidden attribute to hide generated content from assistive technologies (as you are using an icon font family, there is a generated character :before of :after). According to the specs:

    Authors MAY, with caution, use aria-hidden to hide visibly rendered content from assistive technologies only if the act of hiding this content is intended to improve the experience for users of assistive technologies by removing redundant or extraneous content. Authors using aria-hidden to hide visible content from screen readers MUST ensure that identical or equivalent meaning and functionality is exposed to assistive technologies.


    I don't know your exact use case, so I take the liberty to use the simpler case of providing a phone number. In decreasing order of preference, I would use:

    
      
      +33 7 1234576
    
    
    (or any variation implying:
      - an `i` element with a `role` presentation attribute
        instead of the inner `span` element
      - a `title` attribute instead of an `aria-label` attribute)
    
    +33 7 1234576
    
    (or any variation using `title` instead of `aria-label`)
    
    +33 7 1234576
    
    (or any variation using `title` instead of `aria-label`)
    

    Please note that aria-label and title attributes should describe the content of the element. Not the next sibling element. So I feel like the following solution is not in accordance with the specs (even if most accessibility tools would actually have the same observable behavior as if the phone number were actually inside the span element) :

    +33 7 1234576
    

提交回复
热议问题