Next.js image fallback

How to Handle Missing Images in Next.js

Next.js apps often render images from CMS data, ecommerce catalogs, user uploads, and remote APIs. fallback.pics gives you stable SVG placeholder URLs for missing image states.

Example URL https://fallback.pics/api/v1/600x600?text=Product+Image
Next.js image fallback example generated by fallback.pics

Guide section

Use a fallback URL when source data is missing

Before rendering an image, check whether the source exists. If it does not, use a fallback.pics URL that matches the expected dimensions.

Use a fallback URL when source data is missing tsx
const imageSrc =
  product.imageUrl ||
  "https://fallback.pics/api/v1/600x600?text=Product+Image";

Guide section

Handle failed loads in a client component

If remote images can fail after render, use a client component with local state and an error handler.

Handle failed loads in a client component tsx
"use client";

import { useState } from "react";
import Image from "next/image";

export function SafeImage({ src, alt }) {
  const fallbackSrc = "https://fallback.pics/api/v1/600x600?text=Product+Image";
  const [currentSrc, setCurrentSrc] = useState(src || fallbackSrc);

  return (
    <Image
      src={currentSrc}
      width={600}
      height={600}
      alt={alt}
      unoptimized
      onError={() => {
        if (currentSrc !== fallbackSrc) setCurrentSrc(fallbackSrc);
      }}
    />
  );
}

Guide section

Choose placeholders by surface

Use product placeholders for commerce pages, avatar placeholders for account UI, skeleton placeholders for temporary loading states, and Image unavailable copy when a final asset cannot be displayed. The currentSrc guard prevents repeated fallback state updates.

Choose placeholders by surface tsx
const fallbackBySurface = {
  product: "https://fallback.pics/api/v1/600x600?text=Product+Image",
  avatar: "https://fallback.pics/api/v1/avatar/200?text=JD",
  banner: "https://fallback.pics/api/v1/banner/1200x400?text=Banner"
};

Use fallback.pics as your default missing-image URL in Next.js.

https://fallback.pics/api/v1/600x600?text=Product+Image
View API Reference