nuxt / nuxt/image

Using image width and height in case of responsive images

Open
#332 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.5k
Forks
331
Avg merge
19h 52m
Merged PRs (30d)
9

Description

<nuxt-img
            src="/images/abc.png"
            sizes=" xl:100vw xxl:100vw xxxl:100vw"
 />

works fine but in lighthouse, it generates an warning like the following -
Set an explicit width and height on image elements to reduce layout shifts and improve CLS

As per this documentation -
https://image.nuxtjs.org/components/nuxt-img
Use original image width/height for responsive images (when using sizes)

Width of my actual image is 1930 and height is 333
So when I try to add width and height as 1930 and 333, the image is not responsive anymore. Am I missing something here ? please advise.

<nuxt-img
            src="/images/abc.png"
            width="1920"
            height="333"
            sizes=" xl:100vw xxl:100vw xxxl:100vw"
          />

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the nuxt-img component and compare the documented responsive-image behavior with the supplied width, height, and sizes attributes. Reproduce the Lighthouse warning using the example values, then verify that the final behavior preserves responsiveness while providing the explicit dimensions Lighthouse expects.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxt
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.