Back to templates

Template details

Using a fallback image with next/image

Learn how to use a fallback image while using the next/image component.

About this template

The image-fallback example is a Next.js boilerplate from Vercel that demonstrates how to render a fallback image whenever the next/image component fails to load the requested image source.

What is the image-fallback example?

The image-fallback example is a minimal Next.js project that shows a common pattern for handling broken image URLs in production. Input is a Next.js app with an image component whose source can fail; output is a rendered page that swaps in a fallback image automatically. The template runs on Next.js, is styled with Tailwind CSS, and lives in Vercel's curated examples repository, which currently has over 5,100 GitHub stars.

Key Features

  • Next.js framework — Built with Next.js, so it can be deployed to Vercel or any other platform that supports Next.js.
  • next/image component — Uses the built-in next/image component, which provides automatic image optimization, lazy loading, and responsive width and height handling.
  • Fallback image logic — Shows how to attach a runtime error handler to the image component so a backup image appears when the primary URL errors.
  • Tailwind CSS styling — Includes Tailwind CSS as the utility-first styling system for the demo page.
  • One-click Vercel deploy — A deploy link clones the repository straight into Vercel with preset project and repository names.
  • create-next-app bootstrap — Can be initialized locally with pnpm create next-app using the example URL, giving you a ready-to-run project.
  • Live demo — A hosted demo at solutions-image-fallback.vercel.app lets you see the fallback behavior in action before you clone.

Who is it for?

The template is for Next.js developers who need to handle remote image failures gracefully in their applications. It is also for frontend engineers learning the next/image component's error handling patterns, and for teams building image-heavy sites that want a reliable fallback strategy before shipping to production.

What can you do with it?

  • Next.js app developers: adapt the fallback logic for product images, user avatars, or marketing graphics where a broken URL would otherwise show a broken-image icon.
  • Frontend teams: use the template as a starting point for a reusable image component with built-in error recovery.
  • Vercel users: deploy the sample instantly to inspect production behavior, then modify the code for their own projects.

How does it work?

The example implements a fallback by hooking into the image component's error event. When the browser fails to fetch the specified source URL, the handler updates the displayed source to a fallback image, and the page continues rendering normally. The exact wiring is visible in the repository's source files, and the one-click deploy URL makes the working result available immediately.

screenshot of Using a fallback image with next/image on template0.com