-
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 Tests Image Tag complains about no width and height #12712
Comments
@gigaboy I think it's asking for you to add width and height attributes:
Transferring this issue over to the Lighthouse repo. |
Correct, Lighthouse is asking to add width and height to the src= string, but all the specs I've looked at don't show that its needed. In my case anyway, adding these variables causes the problem described. |
width and height are not needed to make the image display. But without them, the image may cause the page to shift its content, which is bad for core web vitals and may negatively impact search ranking.
Can you show your complete snippet, including the width and height attributes that you used? It's also worth noting that if you're on a 2x DPR display, then the browser will select a higher quality image. |
Based on our documentation and some brief testing, it looks like sizes in |
Attached are testbed files along with screenshots. See code in index.html, tests #1, 2 and 3 and corresponding screenshots. I zipped this all up to make it more portable. |
This is WAI because a layout shift is still possible as the image loads in. |
Describe the bug
This code, according to many sources, is correctly formatted, and shows no CLS, which is good. There is no defined underlying CSS for this img:
Problem
Lighthouse performance complains that:
"Image elements do not have explicit width and height".
However, if I insert a width and height into the src"...", the error goes away, but then executing the code ignores all of the srcset/sizes variables and only uses the src, regardless of screen size. I have tried changing the order of the min widths (and even changing them to max-widths). Same problem. I have also tried
<picture>
tags, but with same result.Expected behavior
The text was updated successfully, but these errors were encountered: