Is alt the same as alt=""?
Asked Answered
W

1

9

I'm adding alt attributes to all my images to improve SEO/screen reader performance.

Per best practice, images that are purely aesthetic should have an empty alt attribute alt=""so screen readers skip over them. I'm in WordPress and noticed it does add alt to these descriptionless aesthetic images, but not alt="".

Does alt get read the same as alt="" by screen readers and search engine crawlers, or should I go in and programatically force an alt=""?

Wrung answered 26/6, 2017 at 16:36 Comment(1)
I think that's a stretch - sure SEO is involved but it's also a specific question about HTML and how it gets read. Anyone with a similar question for various reasons can look at this question and learn about Empty Attribute Syntax. Specific code is being referenced here - I think this belongs.Wrung
G
15

Yes, it's the same: https://html.spec.whatwg.org/multipage/syntax.html#attributes-2

Empty attribute syntax

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

To me, that says that an attribute with no value is the same as having a value of empty string.

This answer says the same.

Goofy answered 26/6, 2017 at 16:40 Comment(2)
Ahh, googling 'Empty attribute syntax' was very helpful - I've never used that phrase before. Here's another good post w/ a link to a validator to test which attributes can be used this way: https://mcmap.net/q/1173474/-for-which-html5-attributes-is-the-quot-empty-attribute-syntax-quot-allowed Thanks KarlReid!Wrung
I didn't know it either before today, I guess I just got lucky with my googling and found good information.Goofy

© 2022 - 2024 — McMap. All rights reserved.