-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lighthouse warns when an anchor tag is just a placeholder #15820
Comments
Yeah I think we can discuss changing this. Although the link is not crawlable this doesn't appear to be a bad practice that search documentation warns against.
Not sure what you are referring to here, what differences did you noticed between anchor tags containing images vs text? |
This triggers a warning: <a>
<img src="https://picsum.photos/200/300" alt="" width="200" height="300" loading="lazy">
</a> This does not: <a>
Hello
</a> |
The audit fails for me here as well. Not noticing any difference between images/text. |
You are right! I was testing with an anchor element that also had an |
href
attribute and does contain an image tag.
Thank you for updating the title. This better reflects the issue. |
relevant spec
Agreed we should not flag We should still call it out if it has any of these must-not-be-present attributes when href is missing. Thanks for bringing this to us! |
This is a very interesting discussion. I agree that pointing out Looking at the already closed PR #15894, it seems too complex to resolve quickly. Because, Thank you for reading! Related specs: |
FAQ
URL
https://www.romainmenke.com/lighthouse-bug-anchors-without-href-attribute/without.html
What happened?
I used an anchor tag without an
href
attribute and placed an image inside:Our actual template code looks much more like :
And then I got this error:
There are a bunch of warnings on that page but only
Links are not crawlable
is relevant to this issue.What did you expect?
The HTML specification clearly envisions a dual mode for anchor elements.
Either they have an
href
attribute, which makes them true anchor elements or they do not, in which case they represent a placeholder.This concept is also used in CSS for the location pseudo classes : https://drafts.csswg.org/selectors/#the-any-link-pseudo
These only match anchors that do have an
href
attribute.When templating (server-side) it really helps to be able to wrap a bunch of html with an anchor tag and optionally give it an
href
attribute only when it needs to be a link.This makes the variable part in the template much smaller (only 1 attribute).
I expect Lighthouse to embrace the relevant specifications and to not give any warnings here.
I also expect Lighthouse to have consistent behavior between anchor tags withouthref
when they contain text vs. when they contain images.What have you tried?
N/A
How were you running Lighthouse?
Chrome DevTools
Lighthouse Version
latest
Chrome Version
latest
Node Version
N/A
OS
N/A
Relevant log output
The text was updated successfully, but these errors were encountered: