Skip to content
Technical checks

How to find broken images on your website and catch new ones

A failed image now leaves a tidy empty box instead of an icon, so nobody reports it. A console snippet that scrolls the page and lists every failed image, the srcset trap, and the deploy habits that cause them.

Dalius Pamedytis CEO of Rookflare
Published
Reading time
5 min read
404 in large type above the failing image request, beside the Lumen Studio demo with its empty image frame marked and a Low card naming the broken image.

Key takeaways

  • Scroll the whole page first, or lazy-loaded images never get a chance to fail.
  • Check naturalWidth as well as the status code; a 200 does not prove the image works.
  • Test at a phone width and a desktop width, because srcset can load a different file on each.
  • Renamed asset paths, cached HTML and letter case in file names cause most new breakage.

To find broken images on a page, scroll to the bottom so lazy images load. Then list every image that finished loading with a width of zero. A short console snippet does both, and the browser’s Network panel shows the status code of each failed request. Repeat it at a phone width, because responsive images can load a different file on small screens.

Find broken images on one page with the console

Open the page, open the browser console and paste this snippet. It scrolls down one screen at a time, waits briefly at each step, then lists the images that failed:

for (let y = 0; y < document.body.scrollHeight; y += innerHeight) {
	scrollTo(0, y)
	await new Promise((resolve) => setTimeout(resolve, 300))
}
console.table(
	[...document.images]
		.filter(
			(img) => img.complete && img.naturalWidth === 0 && img.currentSrc !== '',
		)
		.map((img) => ({ src: img.currentSrc, alt: img.alt })),
)

Two browser properties do the work. MDN’s page on the complete property explains that complete is true for a broken image as well as a loaded one. The naturalWidth property tells them apart: it is 0 when the browser has no image data to measure.

That is why the check looks at pixels instead of status codes. A server can answer 200 with an HTML error page or an empty file, and the image still shows nothing.

One exception: an SVG without its own width and height can report a naturalWidth of 0 and still display. Open any SVG in the list before treating it as broken.

Check failed image requests in the Network panel

The console snippet tells you which images failed. The Network panel tells you why. Open it, tick “Disable cache”, filter by “Img” and reload. Sort by the Status column and look for anything in the 400s or 500s.

Chrome’s Network panel reference covers the filters. The usual answer is a 404: the file is gone or renamed. A 403 means a bucket or hotlink rule refuses it. A request with no status at all failed earlier, for example a blocked mixed-content image on an HTTPS page.

Test at a phone width and a desktop width

Responsive images use srcset and sizes so the browser can choose a smaller file on a phone. The result is that one image tag can request a different file at each width. MDN’s guide to responsive images shows how the browser picks.

If one of those files is missing, only some screen sizes break. Run the snippet at a phone width in device mode, then at a desktop width. The currentSrc column shows which file each width actually used. Other bugs that only appear at one width are collected in mobile vs desktop layout bugs.

Why broken images appear after deploys

New broken images cluster around releases, and the causes repeat. The table pairs each cause with the fix that stops it coming back.

Cause Symptom Fix
Hashed asset names change with each build Cached HTML points to files the deploy deleted Keep the previous build’s assets for a day after a deploy
File name differs only in letter case Works on a laptop, 404 on a case-sensitive server Lowercase file names, enforced by a lint rule or build step
One srcset entry missing Broken only at some widths Generate every size in the build, never by hand
CMS migration moved the media folder Old posts break, new ones work Redirect the old media path, then rewrite the references
Image CDN or bucket rules changed 403 on every image from one host Check the CDN’s allowed referrers and bucket policy

The first row is the most common after a deploy. A visitor who loaded the page before the release still has HTML that names the old files. If the server deletes them at once, that visitor sees empty boxes until they reload.

Find broken images on a whole website

The console snippet covers one page at a time, which is enough for one page per template after a release. For a whole website, a crawler that reads every page and checks every image address saves hours.

The free broken link checker reads the <img src> addresses in a page’s HTML. It reports each image and link that returns an error. It reads the HTML as delivered. Images added by JavaScript, srcset candidates and CSS background images are outside what it sees, so keep the browser check for those.

For hundreds of pages, a desktop crawler such as Screaming Frog SEO Spider is one option. It checks the response code of each image in an <img> element, and its Response Codes tab filters the client errors (4xx). The free version stops at 500 URLs and does not render JavaScript, so script-added images stay a browser job there too.

Broken images are one row on the checklist for the hour after a deploy. Run the snippet on one page per template right after each release.

Catch new broken images on a schedule

Rookflare checks images on every scan of a monitored page. It loads the page in Chromium at desktop and mobile width and scrolls through it so lazy images load. It then records image requests that fail or answer with a 4xx or 5xx status, and images that finished loading with no pixels. Each broken image opens one issue for the website, even when it appears on several pages. The website health monitoring page lists the other checks that run in the same scan.

Rookflare does not check alt text and does not judge whether the right image is shown. A wrong but working image is a visual change, which a screenshot comparison against an approved baseline shows instead.

Questions

Does a 200 status code mean the image works?

No. A server can answer 200 with an error page, an empty file or a format the browser cannot decode. Check naturalWidth in the browser as well.

Why does an image work for me but not for visitors?

Your browser may still have the old file cached, or you are seeing a different srcset candidate. Reload with the cache disabled and test at a phone width.

Are broken images bad for SEO?

A broken image cannot appear in image search, and an empty box where a product photo belongs hurts the page for visitors. Fixing it is worth it for the visitors alone.

Share this article

Written by

Dalius Pamedytis

CEO of Rookflare

Dalius is the CEO of Rookflare and the engineer who builds it, from the Playwright scanner that captures every page to the dashboard where you review what changed. Day to day he also works on large marketing websites and dashboards, so he has seen how a quiet release can break a checkout button or a sign-up form. He writes about what actually breaks on real websites and the simplest way to catch it before your visitors do.

More from Dalius Pamedytis

Keep reading

Run a free check on your website

See in under a minute whether a page answers, has a valid certificate and working links. It is a one-time check of one page, free and without signup.

Or start the free trial, no card needed. Rookflare then checks your site every day and alerts you when something breaks. From €19 a month (provisional).