Skip to content

Image component sizes property does not work #18413

@josepholiveira

Description

@josepholiveira

Bug report

Describe the bug

When using the Image component, the sizes property doesn't work as described in the docs.

When using the Image component, the image is resized to match the container width which is size of the width attributes that we passed, or fit 100% of the viewport if the image is larger than the screen, ignoring the sizes attribute completely.

Example of code:

<Image
      width="800px"
      height="456.8px"
      sizes="(max-width: 500px) 100px"
      src="/next.png"
      alt="Next.js"
    />

To Reproduce

I created a codesandbox example with the exact problem:

  1. Go to https://codesandbox.io/s/elated-neumann-u81mr?file=/pages/index.js
  2. Resize the browser window width to be bigger than 500px to see that the image is the size of width 800px and height 456.8px
  3. Resize the browser window width to be smaller than 500px to see that the image will fit to 100% of the screen, not respecting the sizes prop that should tell the image to be 100px

Expected behavior

I expect the image to have exactly a 100px when the view port is smaller then 500px, respecting the sizes attribute.

Screenshots

Bigger viewport width
bigger-viewport

Smaller viewport width
smaller-viewport

System information

  • OS: Ubuntu 20.04
  • Browser: Chrome
  • Version of Next.js: 10.0.0
  • Version of Node.js: v12.18.3

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions