HTML5 i tag validity with icons

前端 未结 2 1821
孤独总比滥情好
孤独总比滥情好 2020-11-30 16:07

I have been using Bootstrap to build my site, but in doing so and researching SEO, I\'ve discovered that using the i tags with glyphicons is not technically \"v

相关标签:
2条回答
  • 2020-11-30 16:36

    Don’t use i.

    The i element has a meaning which isn’t appropriate for general icons:

    […] a span of text in an alternate voice or mood, or otherwise offset from the normal prose in a manner indicating a different quality of text, such as a taxonomic designation, a technical term, an idiomatic phrase from another language, transliteration, a thought, or a ship name in Western texts.

    Reasons why some people use(d) i as hook for showing icons (via CSS) might be:

    • The term "icon" starts with i.
    • The element name is short.

    Use span instead, which is a meaningless element.


    If the icon is relevant content (important for understanding/using your page), consider using the img element instead, which allows you to use the alt attribute.

    You should use CSS for decorative icons only. If that’s not possible:

    If you link this icon and the link doesn’t contain any content (no text, no img, …), i.e. it only contains an empty element, then you should provide some content in the HTML. Otherwise, visitors without CSS support, screen reader users, etc. won’t be able to use your link. If you don’t want to include content for design reasons, hide it visually. More details in my related answer.

    0 讨论(0)
  • 2020-11-30 16:37

    You can use something like <span class="sr-only">Your Text</span> to improve the accessibility.

    .sr-only is a built-in Bootstrap class to make it easier to provide useful text to screen readers when you also do not want that text to appear visually on the screen.

    0 讨论(0)
提交回复
热议问题