Skip to content
WANCRAFT

E.110Backgrounds & Effects

Light Rays

Soft volumetric god rays fanning from a light source, swaying slowly with drifting dust motes.

NewReactCSSTailwindintermediate

Overview

Light Rays stacks three conic-gradient layers of soft beams that fan out from a light source at the top, a top corner or a custom point, aimed at the bottom centre of the container. Each layer sways around the source on its own slow cycle with the Web Animations API, so the motion is composited on the GPU and the main thread does no per-frame work. A radial mask fades the beams with distance, a hot spot marks the source, and optional dust motes drift and glint inside the light. A mouse pointer nudges the whole source a few pixels. Beam layouts are seeded, so server and client render identical gradients; everything pauses offscreen and in hidden tabs, and reduced motion holds a still frame.

01Installation

Method 01 · Registry

CLI verified

Uses the shadcn CLI in a project initialised with shadcn init. Installs the file to components/ui/light-rays.tsx and adds its dependencies.

npx shadcn@latest add https://wancraft.my/r/light-rays.json

Method 02 · Copy and paste

  1. 1. No extra dependencies — React and Tailwind CSS only.
  2. 2. Copy the source from the Code tab into components/ui/light-rays.tsx.
  3. 3. Import it and adjust props.
Dependencies
None
Peer
react ≥ 18, tailwindcss ≥ 4
Added
13 Oct 2026
Updated
—

02Usage

The default configuration. Change properties above to generate a tailored example in the Usage tab.

example.tsx
import { LightRays } from "@/components/ui/light-rays";

export function LightRaysExample() {
  return (
    <div className="relative h-80 w-full overflow-hidden rounded-xl">
      <LightRays />
    </div>
  );
}

03Props

PropTypeDefaultDescription
rayCountnumber12Beams per layer (three seeded layers are stacked).
spreadnumber70Angular width of the beam fan in degrees (5–180).
intensitynumber0.6Overall beam strength, 0–1.
speednumber1Sway and dust speed multiplier; 0 holds the rays still.
colorstring"#FF7448"Light colour (any CSS colour, mixed with color-mix()).
source"top" | "top-left" | "top-right""top"Where the light comes from.
sourceX / sourceYnumber—Custom source position in % of the container; overrides source. The fan aims at the bottom centre.
dustbooleantrueFloating dust motes inside the beams.
pointerbooleantrueA mouse or pen pointer nudges the source up to 28px.
childrenReactNode—Optional content layered above the light.
...propsHTMLAttributes<HTMLDivElement>—Forwarded to the root, which is absolute inset-0 — place it inside a positioned parent.

04Features

  • 01Pure CSS rendering: three seeded conic-gradient layers and a radial distance mask — no canvas
  • 02Composited sway via the Web Animations API; no per-frame JavaScript while idle
  • 03Top, corner or custom source; the fan re-aims at the bottom centre for the container's aspect ratio
  • 04Optional dust motes that drift and glint in the beams
  • 05Pointer nudges the source with an eased rAF loop that stops once settled
  • 06Animations pause offscreen and in hidden tabs; softer mix on light themes
motion · continuousinput · pointerinput · viewport

05Accessibility

  • All light layers are aria-hidden and ignore pointer events; layered content stays fully interactive.
  • prefers-reduced-motion renders a still frame: no sway, no dust drift and no pointer shift.
  • Only mouse and pen pointers move the source, so touch scrolling never shifts the light.
  • Beams are low-contrast washes; overlaid text keeps its own colour and contrast.

06Limitations

  • Very low intensity on a white background is intentionally subtle; raise intensity or pick a deeper colour for light pages.