Is it correct to use alt tag for an anchor link?

后端 未结 7 1420
深忆病人
深忆病人 2020-11-27 03:33

Is it correct to use alt tag for an anchor link, something like


7条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 04:18

    Such things are best answered by looking at the official specification:

    1. go to the specification: https://www.w3.org/TR/html5/

    2. search for "a element": https://www.w3.org/TR/html5/text-level-semantics.html#the-a-element

    3. check "Content attributes", which lists all allowed attributes for the a element:

      • Global attributes
      • href
      • target
      • download
      • rel
      • hreflang
      • type
    4. check the linked "Global attributes": https://www.w3.org/TR/html5/dom.html#global-attributes

    As you will see, the alt attribute is not allowed on the a element.
    Also you’d notice that the src attribute isn’t allowed either.

    By validating your HTML, errors like these are reported to you.


    Note that the above is for HTML5, which is W3C’s HTML standard from 2014. In 2016, HTML 5.1 became the next HTML standard. Finding the allowed attributes works in the same way. You’ll see that the a element can have another attribute in HTML 5.1: rev.

    You can find all HTML specifications (including the latest standard) on W3C’s HTML Current Status.

提交回复
热议问题