Skip to main content
239

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Themes
Web docs
Layout

Parallax

Moves its direct children with CSS scroll-driven animation while the root crosses the viewport, and stays static under reduced motion.

Frameworks
Astro · React · Elements · Dioxus
Registry
lumen add Parallax
Interaction
Native markup
01

See it and copy it

Framework example

Choose Astro, React, Elements, or Dioxus to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.

AstroCode target · live preview uses Astro
A still mountain lake at dusk with warm light on the peaks
Depth without JavaScript

The framed image drifts inside its clipped frame and this card moves past it while the section scrolls. Reduced motion keeps both still.

View Parallax code

Framework usage

Switch targets to compare the adapter code. This live preview runs the Astro example. Before copying an example, complete the matching framework setup; React, Elements, and Dioxus use their own behavior APIs.Width controls resize the preview container. Resize your browser to test viewport breakpoints.
astro
---
import { Card, Grid, Image, Parallax } from '@santi020k/lumen-astro'
---

<Grid style="align-items: start;">
  <Parallax clip from={-8} to={8} zoom={1.2} style="border-radius: var(--ui-radius-lg);">
    <Image alt="A still mountain lake at dusk with warm light on the peaks" height={960} radius="none" src="/demo-media/lake-dusk.webp" width={1440} />
  </Parallax>
  <Parallax from={10} to={-10}>
    <Card>
      <strong>Depth without JavaScript</strong>
      <p>The framed image drifts inside its clipped frame and this card moves past it while the section scrolls. Reduced motion keeps both still.</p>
    </Card>
  </Parallax>
</Grid>
Edit Parallax in browser

Framework differences

React: The React root is a div; the Astro as prop is not part of the React API. Pass from, to, and zoom as numbers. A style prop is merged with the generated --ui-parallax-* properties.

Elements: lumen-parallax is the root, so its direct children move. Set from, to, and zoom as numeric attributes and clip as a boolean attribute. For a framed photo, compose a native img inside lumen-image.

02

Choose your target

Add this component

Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.

bash@santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
bashAstro wrapper
lumen add Parallax

API reference

Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.

AttributeValuesDefaultDescription
as"div" | "figure" | "section""div"Sets the semantic root. The React root is a div and the Elements root is the element itself.
fromnumber (% of each child's height)-6Starting vertical offset of every direct child as the root enters the viewport, clamped to -50–50. Non-finite values use the default.
tonumber (% of each child's height)6Ending vertical offset as the root leaves the viewport, clamped to -50–50. A column that drifts up past copy uses from={0} to={-20}. Keep unclipped drift modest: a moving child paints above its neighbors and can cover their links.
zoomnumber1Constant scale of every direct child, clamped to 1–1.5, so a clipped image keeps covering its frame while it moves. Cover the travel with at least 1 + 2 × the largest offset (for example zoom={1.08} for ±3), so clipped offsets beyond ±25 cannot stay covered. Without clip, zoom can widen the page; pair it with clip.
clipbooleanfalseClips the moving children to the root's box for framed images. Elements use the boolean clip attribute.
childrenblock or replaced direct childrenrequiredEvery direct child moves with the individual translate and scale properties, so the observed root never moves. Inline boxes and display: contents wrappers do not move, so use block content or media such as img and svg, and give a picture display: block. A figcaption or a nested Parallax root stays put. Lumen owns translate, scale and animation on direct children; wrap a child that already sets them or runs its own animation, such as a ScrollReveal. Parallax follows its nearest scroll container, so an overflow: hidden ancestor stops it.
scroll-driven animation / reduced motionview-timeline on the root, range cover-Pure CSS with no runtime. Children stay in place where scroll-driven animations are unsupported, under the system reduced-motion preference, and inside a data-ui-motion="reduce" ancestor. Content order, reading order and focus never change.
CSS variables--ui-parallax-from / --ui-parallax-to / --ui-parallax-zoomset from propsWritten on the root from the clamped props. Prefer the props; .ui-parallax and .ui-parallax--clip are the documented class hooks.
class, classNamestring""Merges custom classes with the generated ui-* root classes.
...native attributesHTML attributes-Forwards standard attributes to the root element unless the component consumes them.

Customize Parallax

Start with semantic theme tokens and a class on the public component. Keep its accessible name, focus treatment, and interaction state intact.

cssScoped theme overrides
.product-parallax {
  --surface: 0 0% 100%;
  --ink: 220 20% 15%;
  --line: 220 15% 82%;
}

Apply product-parallax through Astro's class, React's className, or the custom element's class. Verify foreground and background contrast in both schemes.

Documented styling parts: parallax parallax--clip

HookValuesDefaultContract
CSS variables--ui-parallax-from / --ui-parallax-to / --ui-parallax-zoomset from propsWritten on the root from the clamped props. Prefer the props; .ui-parallax and .ui-parallax--clip are the documented class hooks.
class, classNamestring""Merges custom classes with the generated ui-* root classes.

Use the documented hooks above and adapter types when targeting component states. Theme guide · Accessibility verification scope


Web docsFull catalog