Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

anchor

alt

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

<a href="#" class="test" alt="Something" src="sfasfs" ></a> 
like image 648
user2067736 Avatar asked Feb 13 '13 09:02

user2067736


People also ask

Which is correct for anchor tag?

The <a> tag defines a hyperlink, which is used to link from one page to another. The most important attribute of the <a> element is the href attribute, which indicates the link's destination. By default, links will appear as follows in all browsers: An unvisited link is underlined and blue.

Should links have alt tags?

In order for a link to be readable by screen reader users links must all contain either plain text, or in the case of a linked image, alt text describing where the link goes.


2 Answers

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.

like image 172
unor Avatar answered Sep 21 '22 06:09

unor


For anchors, you should use title instead. alt is not valid atribute of a. See http://w3schools.com/tags/tag_a.asp

like image 45
tomis Avatar answered Sep 18 '22 06:09

tomis