ESLint warns 'Do not use <img>' in a Next.js project
Do not use <img>. Use Image from 'next/image' instead.Short answer
The rule @next/next/no-img-element flags a plain img tag because next/image gives smaller files and a faster Largest Contentful Paint. Replace the tag with Image from next/image, giving it width and height. If you must keep img, use unoptimized, a picture element, a custom loader, or turn the rule off.
Fix it fast
1Find out which cause you have
Find every place the rule fires so you can decide per image.
npx eslint .2Match what you see, then jump to its fix
- 1
@next/next/no-img-element on a normal content imageA plain img tag is used where next/image would workFix - 2
Optimised images cost money on your host, or you must serve the original fileYou want the component but not the optimisationFix - 3
Many img tags are intentional and the warnings are noiseThe rule is too strict for this projectFix
- 1
What does the error look like?
Do not use <img>. Use Image from 'next/image' instead.@next/next/no-img-element
Cause 1 of 3
A plain img tag is used where next/image would work
1Check
The rule exists because an img element means slower LCP and more bandwidth than the optimised component.
grep -rn "<img" app components pages2Fix
Import Image from next/image and give it src, alt, width and height.
import Image from 'next/image'
<Image
src="https://example.com/hero.jpg"
alt="Landscape picture"
width={800}
height={500}
/>3Verify
Lint again; the warning for that file should be gone.
npx eslint .Confirmed by nextjs.org
Cause 2 of 3
You want the component but not the optimisation
1Check
Next.js notes that managed hosts may charge for optimised images, and self-hosting needs sharp and cache storage.
grep -rn "unoptimized" app components pages2Fix
Keep next/image but pass unoptimized, or use a picture element with a nested img, or set a custom loader in next.config.js.
<Image {...props} unoptimized />
// next.config.js
module.exports = {
images: {
loader: 'custom',
loaderFile: './my/image/loader.js',
},
}3Verify
Run lint and load the page.
npx eslint .Confirmed by nextjs.org
Cause 3 of 3
The rule is too strict for this project
1Check
The rule is part of eslint-config-next. Rules can be changed in the rules block of the flat config.
cat eslint.config.mjs2Fix
Turn the rule off, or leave it as a warning, in eslint.config.mjs.
import { defineConfig } from 'eslint/config'
import nextVitals from 'eslint-config-next/core-web-vitals'
export default defineConfig([
...nextVitals,
{ rules: { '@next/next/no-img-element': 'off' } },
])3Verify
Run ESLint; no no-img-element reports remain.
npx eslint .Confirmed by nextjs.org
How do I stop it coming back?
- Use next/image by default for content images.
- Pass width and height, as the docs example does.
- Check your host's pricing for optimised images before switching a large site.
- Disable the rule per file, not globally, when only a few images need img.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Web apps
next/image shows nothing for an image from another domain
next/image shows a broken image only for external src values
next/image only optimizes remote images that match an entry in images.remotePatterns in next.config.
3 causes, each with a fixWeb apps
AuthUserPoolException: Auth UserPool not configured in a Next.js app
Auth UserPool not configured
The error means an Amplify Auth call ran before Amplify.configure did.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Clerk cannot read its publishable key in a Next.js app
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY is undefined
Clerk reads NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY.
3 causes, each with a fixWeb apps
The shell cannot find create-next-app
command not found: create-next-app
create-next-app is not meant to be installed as a shell command.
2 causes, each with a fixWeb apps
ESLint fails with: Cannot find module 'next/babel'
ESLint stops on the first file with a Babel or parser error instead of listing lint results
next/babel is a Babel preset that ships inside the next package.
3 causes, each with a fix