Is >

2019-03-02 22:50发布

<img src="[srcpath]" alt="">
<img src="[srcpath]" alt>

That is to say:

Are those both considered null values for image alt text? Or must you ensure the alt="" is present?

2条回答
家丑人穷心不美
2楼-- · 2019-03-02 23:21

Both have the empty string as value, so they are equivalent.

HTML5 defines that attributes can be specified in four different ways, among them the "Empty attribute syntax":

Just the attribute name. The value is implicitly the empty string.

查看更多
Rolldiameter
3楼-- · 2019-03-02 23:29

You should use the alt="" attribute. Each example of the null alt attribute in the specs for providing alternative text for an image explicitly uses it. Here's another resource on the empty alt="" attribute

However.. if I were to look at the DOM inspector in Chrome and look at an img that had alt="" in the source code, I would see <img src="[srcpath]" alt>.

The Failure Criterion F65 in the WCAG 2.0 standards note that the presence of the alt attribute is sought. It does not clarify whether or not the alt attribute must be explicitly declared as empty (alt="") for HTML5 standards, and as long as you're using the HTML according to the spec, having <img src="[srcpath]" alt> would technically be considered accessible.

So in summary - yes, they technically are the same when it comes to accessibility, but I'm not one to derive from given instruction. By using alt="", you are being aware of the purpose of the alt attribute, and keeping consistency in your alt techniques with respect to the HTML specifications.

查看更多
登录 后发表回答