Installation
npx logic2b@next add parallaxUsage
Give the container a height and put an oversized, object-cover image (or a
gradient) inside. The inner layer drifts as the section passes through the
viewport:
import { Parallax } from "@/components/ui/parallax"
<Parallax range="16%" className="h-72 rounded-xl">
<img
src="/hero.jpg"
alt=""
className="size-full object-cover"
/>
</Parallax>
How it works
The drift is driven entirely by CSS scroll-driven animations
(animation-timeline: view()) — there is no JavaScript on the scroll path and
nothing to throttle. The layer is intentionally taller than the container (by
range on each side) so the movement never reveals an edge, and the container
clips it with overflow-hidden.
Progressive enhancement
The animation lives inside @supports (animation-timeline: view()), so browsers
that don’t support scroll-driven animations simply render the layer static —
the content is always visible, the motion is a bonus. It also honors
prefers-reduced-motion, holding the layer still for users who ask for less
motion.
Live playground
Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.
<Parallax
range="12%"
className="h-48 w-full max-w-lg rounded-xl border"
>
<div
className="flex h-full min-h-64 items-center justify-center bg-gradient-to-br from-primary/20 via-muted to-primary/5 text-sm font-medium"
>Scroll-linked layer</div>
</Parallax>API reference
Generated from the public TypeScript exports in src/ui/parallax.tsx.
ParallaxProps
Typeinterface ParallaxProps extends React.ComponentProps<"div"> { /** How far the layer drifts, any CSS length/percentage. Default `"12%"`. */ range?: string }Parallax
ComponentProps: ParallaxProps| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
range | string | No | "12%" | How far the layer drifts, any CSS length/percentage. Default `"12%"`. |
Accessibility contract
Machine-readable behavior and consumer responsibilities for parallax.
- Support
- Composition contract
- Pattern
- decorative parallax
- Motion scroll transforms
Built-in semantics
- Preserves the semantics of the rendered layer; decorative layers can be hidden from assistive technology.
Consumer responsibilities
- Use empty alt/aria-hidden for decorative imagery, retain a static layout and disable the transform for reduced-motion users.
Known limitations
- • Parallax movement can cause vestibular discomfort unless reduced-motion preferences are honored.