Is it correct to use alt tag for an anchor link, something like
<a href="#" class="test" alt="Something" src="sfasfs" ></a>
Such things are best answered by looking at the official specification:
go to the specification: https://www.w3.org/TR/html5/
search for "a
element": https://www.w3.org/TR/html5/text-level-semantics.html#the-a-element
check "Content attributes", which lists all allowed attributes for the a
element:
- Global attributes
href
target
download
rel
hreflang
type
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.