Parallax Image

Scroll-linked parallax effect for images or content. Moves children on scroll for depth.

Component

↓ scroll

Mountain lake
Forest path
Desert dunes
Ocean waves
Snowy peaks
Autumn valley
Tropical beach
Foggy hills
Canyon view
Rice terraces
Northern lights
Waterfall
Lavender field
Rocky coast
Misty jungle
Salt flats

Installation

pnpm dlx shadcn@latest add "https://pulkitxm.com/components/parallax-image.json"

Usage

Import

Add the ParallaxImage import.

import { ParallaxImage } from "@/components/parallax-image";

Use

Wrap your image or content.

<ParallaxImage>
  <img src="/hero.jpg" alt="Hero" />
</ParallaxImage>;

Guidelines

  • Give the container a height (e.g. min-h-48, h-64) for the effect to be visible.
  • Use intensity to control how far the content moves (default 50px).
  • Works with images or any content; images get object-cover by default.

Props

PropTypeDefaultDescription
childrenReact.ReactNodeContent to apply parallax to (typically an image).
classNamestringAdditional CSS classes for the container.
intensitynumber50Parallax movement in pixels. Higher = more movement.
containerRefReact.RefObject<HTMLElement | null>undefinedRef to a scrollable overflow container. Omit to track window scroll instead.

Examples

Single image

Wrap a single image for a scroll-driven parallax effect.

↓ scroll

Mountain lake
import { ParallaxImage } from "@/components/parallax-image";

export function ParallaxBasic() {
  return (
    <ParallaxImage className="h-56 w-full">
      <img
        src="/hero.jpg"
        alt="Hero"
        className="size-full object-cover"
      />
    </ParallaxImage>
  );
}

With container ref

Pass containerRef when scrolling inside an overflow container instead of the window.

↓ scroll

Mountain lake
Forest path
Desert dunes
Ocean waves
import { useRef } from "react";
import { ParallaxImage } from "@/components/parallax-image";

const IMAGES = [
  { src: "/img-1.jpg", alt: "Mountain lake" },
  { src: "/img-2.jpg", alt: "Forest path" },
  { src: "/img-3.jpg", alt: "Desert dunes" },
  { src: "/img-4.jpg", alt: "Ocean waves" },
];

export function ParallaxGrid() {
  const containerRef = useRef<HTMLDivElement>(null);

  return (
    <div
      ref={containerRef}
      className="h-96 overflow-y-auto"
    >
      <div className="grid grid-cols-2 gap-2 p-2">
        {IMAGES.map((img) => (
          <ParallaxImage
            key={img.alt}
            className="h-36 rounded-md"
            intensity={40}
            containerRef={containerRef}
          >
            <img
              src={img.src}
              alt={img.alt}
              className="size-full object-cover"
            />
          </ParallaxImage>
        ))}
      </div>
    </div>
  );
}

Made with ❤️ by Pulkit & Cursor :)

© 2026 Pulkit. All rights reserved

DMCA Verified

Last updated: