Questions tagged [nextjs-image]

next/image is the built-in image component in NextJS 10. Please, do not use this tag for questions related to the next-images package (use [next-images] instead).

next/image is the Next.js team's solution to performant images on the web. The Next.js Image Component is just a drop-in replacement for the HTML <img> element, evolved for the modern web.

When using the next/image component, images are automatically lazy-loaded, meaning they're only rendered when the user is close to seeing the image. This prevents loading that 30% of images outside of the initial viewport.

The Automatic Image Optimization allows for resizing, optimizing, and serving images in modern formats like WebP when the browser supports it. This avoids shipping large images to devices with a smaller viewport. It also allows Next.js to automatically adopt future image formats and serve them to browsers that support those formats.

Automatic Image Optimization works with any image source. Even if the image is hosted by an external data source, like a CMS, it can still be optimized.

For usage and available props visit https://nextjs.org/docs/api-reference/next/image

310 questions
120
votes
19 answers

How to set the next/image component to 100% height

I have a Next.js app, and I need an image that fills the full height of its container while automatically deciding its width based on its aspect ratio. I have tried the following: This…
Jake
  • 2,090
  • 2
  • 11
  • 24
55
votes
4 answers

How to use Tailwind CSS with Next.js Image

I am trying to use Tailwind CSS in an Next.js project but I cant't use my Tailwind classes with Next.js Image component. Here's my code: Picture of the author
Pranta
  • 2,928
  • 7
  • 24
  • 37
45
votes
13 answers

Got an error Invalid src prop ('here is a link') on `next/image`, hostname "localhost" is not configured under images in your `next.config.js`

I am using the Image component from Next.js (it's a new feature of Next.js). I've tried to give the source URL: {`${API}/user/photo/${blog.postedBy.username}`} But it shows me this error. I also make changes in my next.config.js as module.exports =…
TASKMASTER
  • 831
  • 1
  • 8
  • 15
43
votes
4 answers

Error: Do not use . Use Image from 'next/image' instead. - Next.js using html tag ( with styled components )

I know that in Next.js we have Image component, but the problem I have with it is that I can't use it as a normal HTML tag like . I have to give it a layout, but there's no option to control it as a normal HTML tag, and besides that, I can't…
Diego
  • 421
  • 3
  • 9
  • 34
40
votes
5 answers

next/image does not load images from external URL after deployment

I use the Next.js Image component for image optimization. It works great on dev but it doesn't load images from external URLs in production. What can I do?
Mahdi
  • 526
  • 2
  • 5
  • 16
35
votes
12 answers

How to use Image component in Next.js with unknown width and height

Since version 10, Next.js comes with the built-in Image component which provides the feature of image optimization and resizing image responsively. I like it a lot and I've been using it across my website for images with a fixed size. According to…
bubbleChaser
  • 755
  • 1
  • 8
  • 21
34
votes
3 answers

Next/Image's components are too slow to appear

I'm using Next.js 10.0.7 and next-images 1.7 and big images take some seconds to appear. I'm using the components correctly, you can see bellow, but I think that there is a solution to my problem.
Charles Braga
  • 488
  • 1
  • 4
  • 11
31
votes
4 answers

NextJS Image component with fixed witdth and auto height

I am using NextJS Image component. I want the image to fill 100% width and take as much height as it needs to maintain the aspect ratio. I have tried many different variations of this code but it will not work unless I define a fixed height on the…
Jkaram
  • 611
  • 2
  • 7
  • 13
28
votes
2 answers

How to allow all domains for Image nextjs config?

I have various image url and changes over time (the image are taken for web by url address and not locally or from a private storage). In order to render tag , domains should be passed on to nextjs config. It isn't possible to pass in 100s…
Sai Krishnadas
  • 2,863
  • 9
  • 36
  • 69
26
votes
4 answers

Next Image not taking class properties

I am using Next.js and next/image to display images, but the CSS is not working inside it. The image is in SVG format and I have placed it in the public folder. I am using Tailwind CSS along with this.
vikky
  • 321
  • 1
  • 4
  • 8
24
votes
5 answers

(Next.js) How can I change the color of SVG in next/image?

import Image from 'next/image' ... emtion I want to change the SVG color in next/image. But in CSS, img { fill="#ffffff" } is not working. How can I solve this?
Dann1y
  • 257
  • 1
  • 3
  • 8
23
votes
6 answers

What is the best way to have a fallback image in NextJS?

Recently, I have been working on a project in NextJS which uses the YoutubeAPI to fetch video information, including thumbnail URLs. The thumbnail URL for a full resolution image looks like…
m_ognjen
  • 255
  • 1
  • 2
  • 8
19
votes
9 answers

400 bad request from next/image

So I am trying to display images with next/image's component. However, the images are not being displayed. I believe this is because of a 400 bad request error next/image is giving me. When I click on that URL, it says "The requested resource…
emma
  • 359
  • 1
  • 3
  • 6
16
votes
4 answers

How to remove the wrapper spans from next/image in Next.js?

I'm leaning Next.js and I have found that next/image is wrapping the img with two spans and adding inline style to the img tag which overriding my class style How can I remove the inline style and the wrapper HTML tags like spans and divs? My code…
Jennifer
  • 603
  • 1
  • 7
  • 17
16
votes
2 answers

Failed to parse src error when importing an image in Next.js

I'm trying to import an image in Next.js but I get this error. I don't know what's the problem, could someone here help me about this? The image is located in public folder, this is the Error I get when I run the server. Error: Failed to parse src…
Bukenya KizzaRoland
  • 721
  • 1
  • 7
  • 13
1
2 3
20 21