Parallax cards
A reusable and responsive component that gives each of its children a smooth parallax effect, adding a modern, interactive touch to your website. Perfect for showcasing lists of content blocks, feature cards, or image galleries.
Parallax Cards
Card #1
Parallax Cards
Card #2
Parallax Cards
Card #3
Parallax Cards
Card #4
Parallax Cards
Card #5
API usage
components/parallax-cards.demo.tsx
import { PlusIcon } from "lucide-react";
import { ParallaxCards } from "./parallax-cards";
export function ParallaxCardsDemo() {
return (
<ParallaxCards maxStackedCards={3} top="54px">
<PlaceholderCard index={0} />
<PlaceholderCard index={1} />
<PlaceholderCard index={2} />
<PlaceholderCard index={3} />
<PlaceholderCard index={4} />
</ParallaxCards>
);
}
function PlaceholderCard({ index }: { index: number }) {
function Message({ children }: { children: string }) {
return (
<span className="absolute top-0.75 left-0.75 text-[9px] leading-none sm:text-xs">
{children}
</span>
);
}
return (
<div
className="h-125 p-7 opacity-85 sm:p-10"
style={{ backgroundColor: `var(--chart-${index + 1})` }}
>
<div className="border-foreground relative size-full border border-dashed p-4 sm:p-5">
<Message>Parallax Cards</Message>
<div className="size-full p-3.5 sm:p-5">
<div className="border-foreground relative z-20 size-full border p-4 sm:px-6 sm:py-5">
<Message>{`Card #${index + 1}`}</Message>
<div className="border-foreground relative grid size-full place-items-center overflow-hidden border border-dashed">
<PlusIcon />
</div>
</div>
</div>
</div>
</div>
);
}Installation
CLI (recommended)
1
Run the command below to add the component to your project.
It will also generate the required base stylesheet if one doesn't already exist and guide you through setting up the import alias
@/components/... if it isn't already configured.pnpm dlx shadcn@latest add https://100xui.com/components/parallax-cards.jsonManual
1
pnpm add clsx motion tailwind-merge2
100xui
components/parallax-cards.tsx
3
API reference
<ParallaxCards/>
| Props | Type | Description | Default value |
|---|---|---|---|
children | | An array of ReactElements to be rendered as individual cards in the parallax sequence. | |
maxStackedCards? | | The number of cards that remain visibly stacked on top of each other before the bottom-most card begins to fade and scroll out of view. | |
top? | | The CSS top offset for the sticky cards. This determines how far from the top of the window each card "sticks" as you scroll. | |
forceParallax? | | If set to true, enforces the parallax effect to run even when the card would be clipped at the bottom of the viewport (i.e., when card height + top offset > viewport height). | |
...rest | | Any standard React div props, like id, style or className, which will be applied directly to the component's root element except for ref. | |
Good to know:The parallax effect prevents content clipping by automatically disabling itself if any card's height plus its top offset exceeds the viewport height. You can override this behavior by setting the Each child element spans the height of the tallest sibling, ensuring consistent sizing across children, preventing visual mismatches, and helping the algorithm deliver an ideal parallax effect.
forceParallax prop as true. This forces the parallax effect to run, but any overflowing part of the card will be clipped by the bottom of the viewport, making it ideal for non-critical or decorative content. Under the hood, this is done by setting the max-height to calc(100vh - ${top}).