LQIP Image for React

Image component with Low Quality Image Placeholder (LQIP). Shows a blurred placeholder that fades into the full image on load.

Component

Remote URL mode (auto 2x2 placeholder)

Static import mode (full + placeholder)

Installation

 

Usage

Import the component

Add the LqipImage import to your file.

import { LqipImage } from "@/components/lqip-image";

Remote URL

Use with a remote URL. The component auto-generates the blur placeholder.

<LqipImage
  src="https://example.com/image.jpg"
  alt="Description"
  width={800}
  height={400}
/>;

Static import

For static imports, provide both full and placeholder images.

<LqipImage
  src={fullImage}
  placeholderSrc={placeholderImage}
  alt="Description"
  width={800}
  height={400}
/>;

Guidelines

  • For remote URLs, the component fetches the same image at 2x2 pixels for the placeholder; no extra asset needed.
  • For static imports, provide a small pre-generated placeholder (e.g. 20x20) as placeholderSrc for best results.
  • Use priority for above-the-fold images to load eagerly.
  • The container needs explicit dimensions when using fill; use a wrapper with aspect-ratio or fixed height.

Props

All props are optional unless marked required. Use these to customize every aspect of the component.

PropTypeDefaultDescription
srcrequiredstring | StaticImageData-Image source. String URL for remote; StaticImageData for static import.
placeholderSrcStaticImageDataundefinedPlaceholder image for static import mode. Required when src is StaticImageData.
altrequiredstring-Accessible alt text for the image.
widthnumberundefinedImage width in pixels. Omit when using fill.
heightnumberundefinedImage height in pixels. Omit when using fill.
classNamestringundefinedAdditional CSS classes for the image element.
containerClassNamestringundefinedAdditional CSS classes for the container.
sizesstringundefinedResponsive sizes attribute for next/image.
prioritybooleanfalseLoad image eagerly (for above-the-fold images).
fillbooleanfalseFill the container. Requires parent with explicit dimensions.
qualitynumberundefinedImage quality (1-100). Passed to next/image.

Accessibility

  • Decorative display component with no interactive controls, buttons, links, or focusable elements, so there is nothing to operate by keyboard.
  • The container carries role img with aria-label set to the alt text, so assistive tech announces the figure as a single image with its description.
  • The blurred placeholder layer is marked alt empty and aria-hidden true so it is not announced separately, while the full image carries the real alt text.
  • The container exposes aria-busy true until the full image fires onLoad, communicating the loading state to assistive technology.
  • The opacity cross-fade does not check prefers-reduced-motion, so it should be guarded to skip the fade and show the image immediately for users who request reduced motion.

Performance

  • The load transition animates only opacity via transition-opacity, which is a compositor-friendly property that avoids layout and paint work.
  • The placeholder uses a static scale transform and a 20px blur filter that are applied once rather than animated, keeping the GPU cost bounded.
  • Both layers render through next/image for automatic optimization, with the full image using native lazy loading unless priority is set to eager.
  • State is driven by a single onLoad callback into one useState flag with no requestAnimationFrame, IntersectionObserver, event listeners, or timers to clean up.
  • There is no reduced-motion or visibility gating on the fade, so the 700ms transition always runs once the image loads.

Examples

Remote URL

Remote URL mode. Auto-generates a tiny 2x2 placeholder from the same URL.

Remote URL mode (auto 2x2 placeholder)

Static import mode (full + placeholder)

import { LqipImage } from "@/components/lqip-image";

export function LqipImageBasic() {
  return (
    <LqipImage
      src="https://example.com/image.jpg"
      alt="Description"
      width={800}
      height={400}
    />
  );
}

Static import

Static import mode. Provide both full and placeholder images.

Remote URL mode (auto 2x2 placeholder)

Static import mode (full + placeholder)

import { LqipImage } from "@/components/lqip-image";
import fullImage from "@/assets/full.webp";
import placeholderImage from "@/assets/placeholder.webp";

export function LqipImageStatic() {
  return (
    <LqipImage
      src={fullImage}
      placeholderSrc={placeholderImage}
      alt="Description"
      width={800}
      height={400}
    />
  );
}

Fill container

Use fill to make the image fill its container.

Remote URL mode (auto 2x2 placeholder)

Static import mode (full + placeholder)

import { LqipImage } from "@/components/lqip-image";

export function LqipImageFill() {
  return (
    <div className="relative h-64 w-full">
      <LqipImage
        src="https://example.com/image.jpg"
        alt="Description"
        fill
      />
    </div>
  );
}

Last updated on Jun 19

Made with ❤️ by Pulkit &

© 2026 Pulkit. All rights reserved

Last updated: