How do I specify an empty alt attribute in React/JSX?
alt
and alt=""
are the same thing. From the spec:
Attributes can be specified in four different ways:
Empty attribute syntax
Just the attribute name. The value is implicitly the empty string.
...
It's true that you typically see this with boolean attributes, but it's not limited to them.
Example:
var imgs = document.querySelectorAll("img");
var alt0 = imgs[0].getAttribute("alt");
var alt1 = imgs[1].getAttribute("alt");
console.log("0 (" + typeof alt0 + "): '" + alt0 + "'");
console.log("1 (" + typeof alt1 + "): '" + alt1 + "'");
<img src="foo.png" alt>
<img src="bar.png" alt="">
It's worth noting that there are only a very few places where a blank alt
is appropriate, but if you're supplying it at all, you're probably someone who's already aware of those places. :-)
Can we also add alt tags? By doing this, we can overcome Google & tools errors notifications
<img src="foo.png" alt="foo">
<img src="bar.png" alt="bar">