Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

ESLint warns 'Do not use <img>' in a Next.js project

ErrorDo 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.

  • Applies to Next.js 15, Next.js 16, ESLint 9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find every place the rule fires so you can decide per image.

    npx eslint .
  2. 2Match what you see, then jump to its fix

    1. 1@next/next/no-img-element on a normal content imageA plain img tag is used where next/image would workFix
    2. 2Optimised images cost money on your host, or you must serve the original fileYou want the component but not the optimisationFix
    3. 3Many img tags are intentional and the warnings are noiseThe rule is too strict for this projectFix

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 pages

2Fix

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

Did this fix it?

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 pages

2Fix

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

Did this fix it?

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.mjs

2Fix

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

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.