问题描述
对锚链接使用 alt 标签是否正确,例如
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:
搜索a
元素":https://www.w3.org/TR/html5/text-level-semantics.html#the-a-element
选中内容属性",其中列出了 a
元素的所有允许属性:
check "Content attributes", which lists all allowed attributes for the a
element:
- 全局属性
href
目标
下载
rel
hreflang
类型
检查链接的全局属性":https://www.w3.org/TR/html5/dom.html#global-attributes
如您所见,a
元素上不允许使用 alt
属性.
您还会注意到 src
属性也是不允许的.
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.
通过验证您的 HTML,系统会向您报告此类错误.
By validating your HTML, errors like these are reported to you.
请注意,以上内容针对 HTML5,即 W3C 2014 年的 HTML 标准.2016 年,HTML 5.1 变成了 下一个 HTML 标准.查找允许的属性的工作方式相同.你会看到 a
元素在 HTML 5.1 中可以有另一个属性:rev
.
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
.
您可以在 W3C 的 HTML 当前状态.
这篇关于将 alt 标签用于锚链接是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!