195

Stained Glass Window Light Effect

£7
or the whole Vault, £99

A leaded stained-glass window that throws coloured sunlight across your page; scroll moves the sun and the pools slide, stretch and soften.

ScrollTrigger advanced
7 more details
webgl-shaderscrubpinningblend-modelightviewport-aware-tickerambient

About this effect

A leaded stained-glass window with the sun behind it, and its light falling across the page. The window is real glass: every pane has its own thickness, streaks, seeds and dust, the lead came is dark with a dull sheen and solder at the joints, two iron saddle bars cross it, and the glass glows far brighter than the page, brightest where the sun sits behind it and dark where the outer wall shades it.

Read the full effect overview

The light comes through. The window's panes land beside it, or below it on a phone, as pools of coloured light: the whole design laid out in light across the warm ground, crisp where it has travelled least and soft where it has travelled furthest, with a faint beam and dust turning in the air between.

Scroll moves the sun through the day. Morning light is low, warm and stretched; at noon the pools gather bright and nearly white through the clear glass; by evening they are long, soft and orange, then fade. The window design is an SVG in your markup, so your own panes and lead lines throw their own light, and any content you place on the page sits under the same light, tinted by the pools as they pass.

Stained Glass Window Light Effect - GSAP animation effect preview

What's included

12 items
  • Real coloured transmitted light: the window's own panes are projected across the page as a light cookie, not a gradient or a blurred copy laid on top
  • The blur grows with distance: each pool is crisp where the light has travelled least and soft where it has travelled furthest
  • Scroll moves the sun from morning to evening: low warm stretched light, short bright noon light, long orange evening light
  • Glass that reads as glass: per-pane thickness, streaks, ream, seeds and dust, a broken view of sky and trees outside, and a bright glow where the sun sits behind it
  • Dark lead came with a dull bevel and solder at the joints, and iron saddle bars that throw their lines into the light
  • The thick outer wall shades part of the glass when the sun is low or high, and that part of the window and its light both fall dark
  • A faint beam with drifting dust in the air between the window and its light
  • Swap the window: any inline SVG of filled shapes becomes glass, with leads drawn for you and painted detail supported
  • Put your own content under the light: it stays real, selectable DOM, tinted by the pools as they pass, and raised elements cast a shadow of the light
  • Window beside the light on wide screens and above it on phones, chosen automatically
  • Three ways to drive it: scroll scrub (pinned or in flow), a time-of-day loop, or a fixed sun
  • Reduced motion fixes the sun and draws one still frame; without WebGL a CSS approximation of the light shows instead

Perfect for

5 use cases
  • Heritage venues, chapels, churches and historic houses
  • Glass studios, artists and craft workshops
  • Galleries, museums and exhibition pages
  • Calm, atmospheric section breaks and story chapters
  • Seasonal and celebration pages that want one quiet, beautiful moment

How it works

3 sections

The page is the surface

One canvas sits over the section with a multiply blend and is the light itself: warm shade everywhere the sun does not reach, the window's colours where it does. Anything you place in the section stays real DOM and is tinted by the light as it passes.

Glass baked from your SVG

The window is an inline SVG of filled shapes. The script rasterises it once and bakes it into glass: each pane gets its own thickness, streaks, seeds and its own bend on the view outside, and the leads become rounded came with solder at the crossings, tied to iron saddle bars. Change a fill or redraw the design and the glass and its light follow.

Light that travels

For every point on the page the shader follows the sun's ray back to the window and reads the glass there, blurred by how far the ray travelled. ScrollTrigger scrubs the time of day; GSAP's ticker draws each frame while the section is on screen, and reduced motion gets a still frame instead.

Plugins ScrollTrigger
Difficulty Advanced
Includes HTML + JS + CSS source, documentation, AI setup prompt, lifetime updates

Lighthouse, as measured

Google Lighthouse on this effect's demo, from the latest scan. A measurement of the demo as shipped, not a promise for your page.

Accessibility
100
Best practices
100

No performance score, on purpose. That figure depends on how you deploy: your server's compression and caching, your CDN, the connection and the device doing the test, none of which the code controls. The same page can score very differently on two consecutive runs, so measure it where it will live.

The Vault opens this source and the whole library.

Each product gives you the HTML, CSS and JavaScript source, the full documentation and an AI setup prompt, licensed for unlimited personal and commercial projects. Every paid product is tested for desktop and mobile layouts, reduced-motion handling, animation cleanup and keyboard controls wherever there is something to operate.

One payment, over 350 products, and future additions to the library.

Documentation

Quick Start

1. Add to your HTML <head>:

In your downloadThe working code for this step, in index.html.

The inline probe is required. Without WebGL the section shows a CSS approximation, with soft pools of the window's colours beside it. Without this probe, that version would paint for the moment it takes three.js to arrive and then swap for the real light. The probe runs before first paint and stamps html.gl when a canvas is coming. The stylesheet then holds the page in shade with the window as dark glass, which is the state the sun rises from.

Reduced motion does not skip the canvas: the light is drawn once, as a still frame. So the probe does not check prefers-reduced-motion.

2. Add the section anywhere in your <body>:

In your downloadThe working code for this step, in index.html.

The demo's index.html holds the full window, ready to copy: a red flower in a blue roundel on a green stem, set in clear diamond quarries inside a red, blue and amber border.

3. Add before the closing </body> tag:

In your downloadThe working code for this step, in index.html.

Why the import map rather than a plain <script src> for three.js: three ships as ES modules only, and its old UMD build logs a deprecation warning on every page load. The shim imports it as a module. The import is dynamic, so a blocked CDN falls back to the CSS approximation. The shim then puts three on window and loads assets/script.js as an ordinary script, so the effect stays a plain file you can drop into any build (or none).

Already using three.js as a module? Skip the shim and make sure window.THREE is set before assets/script.js runs:

In your downloadThe working code for this step, in script.js.

Using It With Your Own Design

What the effect needs from your markup:

  • [data-glass-light] on the section. With the default scroll trigger this is what gets pinned.
  • [data-glass-stage] inside it: the surface the light falls on. The canvas is appended here and sized to it, so it needs a real height (100svh in the demo).
  • One svg[data-glass-design] with a viewBox. Its on-screen box is where the window is: the glass is drawn there and the light is projected from there, so move or resize it with CSS. With the window in the left part of a wide stage the light falls to its right (side); otherwise it falls below (above).
  • .glass-light__fallback, the CSS light for browsers without WebGL. Keep the element and restyle its gradients to suit your layout.

What is only the demo's styling: the window's position and size, the plaster colour (--wall) and the fallback gradients.

CSS the effect depends on:

  • isolation: isolate on the stage, so the canvas's multiply blend stays inside the section.
  • .glass-light__canvas has pointer-events: none, so anything under it stays clickable and selectable.
  • .glass-light.is-baked .glass-light__design { visibility: hidden }. The SVG keeps its box (the script measures it) and stays in the accessibility tree while the canvas draws the glass.

Putting Your Own Content Under the Light

The canvas is a multiply layer over the stage, so anything inside the stage is lit by it: in warm shade where the sun does not reach, coloured where a pool lands. Text stays real DOM, selectable and readable by assistive technology. Place your content where the light will travel, to the right of a window on the left or below a window at the top:

In your downloadThe working code for this step, in index.html.

In your downloadThe working code for this step, in style.css.

Style the content as if it were in full sun, with a pale ground and full-strength ink: the multiply can only darken. data-shade sets how deep the shade is. For body text, keep it at about 0.55 or above, where ink on a pale ground stays above 4.5:1 in the shade. The demo uses 0.78 because it has no text. [data-glass-raised] elements (up to eight) stand a few pixels off the wall and cast a shadow of the light.

Designing Your Window

Any SVG of filled shapes becomes glass. The rules:

  • Every filled shape is a pane. path, polygon, rect, circle and ellipse all work. The fill is the glass colour; it can come from a fill attribute or from your CSS (the script reads the computed fill).
  • Later shapes paint over earlier ones, exactly as the SVG draws.
  • You do not draw the leads. The script strokes every shape with lead came data-lead units wide (in your viewBox units), a little wider or narrower piece to piece as hand-made came is. The shape marked data-glass-frame, the outer boundary, gets a heavier lead. A shape with fill="none" is lead only.
  • Unfilled areas are stone. Anything outside your shapes blocks the sun, so an arched window is simply an arch-shaped design.
  • Painted detail goes on a stroke-only shape marked data-glass-paint: the dark lines glass painters fire onto a pane, such as leaf veins or a border line. It darkens the glass and its light but is not lead. Set its width with the attribute's value (data-glass-paint="1.2").
  • clipPath, mask and defs work and are not treated as panes.
  • Choose colours like glass, not like UI. Deep, saturated fills (ruby #9c1830, cobalt #1b3c97, emerald #1d6b3c, amber #dc9a1f) read as rich panes and throw strong coloured light. Pale near-whites with a tint (#e6ead9, #eee7cf) read as clear glass and throw the bright light that makes the colours sing. Mix both: a window of only deep colours casts a dim, muddy pool.
  • Cut it like a glazier. Leads that run in long continuous lines (a lattice of quarries, a border strip) read as a real leaded light; a jigsaw of unrelated shapes reads as mosaic.
  • Up to 250 shapes each get their own streaks, ream, seeds and thickness. The bake runs once, so the count costs nothing per frame.
  • Keep the SVG's CSS box at the same aspect ratio as its viewBox.

The no-WebGL fallback shows the SVG itself, so the stroke rules in style.css draw its leads there.

Options

All on the [data-glass-light] element.

Attribute Values Default Description
data-layout auto, side, above auto Which way the light falls. side: to the right of the window, travelling right through the day. above: below the window, swinging from one side to the other. auto picks side when the window sits in the left part of a wide stage
data-trigger scroll, time scroll scroll scrubs the sun with scroll position. time loops a whole day on its own, dawn to dusk to night, with no pin
data-sun 0 to 1 unset Fix the sun: 0 morning, 0.5 noon, 1 evening. Overrides data-trigger
data-rest-sun 0 to 1 0.38 Where the sun stands under reduced motion
data-pin true, false true Pin the section while the sun crosses. false scrubs while it scrolls past in the normal flow
data-distance number 1.6 Pinned scroll length, in viewport heights, from morning to evening
data-scrub number 0.8 Seconds the sun takes to catch up with the scroll
data-duration seconds 24 Length of one day with data-trigger="time"
data-intro 0 on Set 0 to start with the sun already out instead of brightening when the glass is ready
data-shade 0.4 to 0.9 0.78 How bright the page is outside the light, as a warm multiply value. Lower is moodier and makes the pools richer; keep it at 0.55 or above under body text
data-light number 1 Strength of the projected light
data-blur number 1 How quickly the pools soften with distance. 0.5 keeps them sharp; 2 makes them dreamy
data-shaft 0 to 2 1 The haze of the beam in the air. 0 removes it
data-dust 0 to 2 1 Dust turning in the beam. 0 removes it
data-raise px 10 How far [data-glass-raised] elements stand off the page, which sets their shadow offset
data-tilt 0 to 2 1 The pointer nudges the sun a little on desktop. 0 turns it off
data-lead viewBox units 4.4 Lead came width
data-lead-colour colour #1c1916 Lead colour as drawn into the glass
data-saddle fractions, comma separated 0.36,0.84 Heights of the iron saddle bars across the window, as fractions of the design's height. They shade the glass and throw their lines into the light. Empty for none
data-dpr number 1.5 (1.25 on touch) Canvas pixel ratio cap

Example: a window that runs through the day on its own

In your downloadThe working code for this step, in index.html.

Example: late afternoon, fixed, sharper pools

In your downloadThe working code for this step, in index.html.

Accessibility

  • The window is described. The SVG has role="img" and an aria-label; write one for your design. The canvas is aria-hidden, and the section carries an aria-label.
  • No controls, no text in the demo. Scrolling is the only input. The pointer nudge is a small extra on desktop and is never needed.
  • Your content stays real. Anything you put under the light is ordinary DOM: readable, selectable and translatable. See "Putting Your Own Content Under the Light" for contrast.
  • Reduced motion: the sun stands still at data-rest-sun and the light is drawn once, with no scrub, no dust and no pin. The section scrolls like any other.
  • Without JavaScript, or without WebGL: the window shows as the SVG in its colours, with soft CSS pools of its colours beside it.

Dependencies

Dependency Version Required
three.js 0.180.0 Yes, as an ES module (see Quick Start)
GSAP core 3.15.0 Yes: the ticker that draws each frame, the sunrise tween, the time-of-day loop, matchMedia and teardown
ScrollTrigger 3.15.0 For data-trigger="scroll": the pin and the scrub on the sun's position

The lighting itself is all in the shader; GSAP decides where the sun is and when a frame is drawn. The effect uses only stable three.js API (WebGLRenderer, WebGLRenderTarget, ShaderMaterial, CanvasTexture, Matrix2), so pinning another version is a one-line change in the import map.

Browser Support

Anything with WebGL 2, which is every current browser. Support is probed before three.js is asked for a renderer. three logs its own failure as console errors before it throws, so a visitor with WebGL disabled would otherwise get a console full of red. With the probe, they get the CSS approximation and a clean console. Import maps are supported everywhere current; in a browser without them the module never runs and the CSS approximation shows.

Performance

One full-screen draw per frame. The projected light takes nine texture reads (a rotated disc at a mip level chosen from the blur), the beam five more, and the window a few. The glass itself (thickness, streaks, ream, seeds, dust, the lead bevel and solder, the saddle bars, each pane's bend on the view outside) is baked once into three textures when the page loads, so none of that runs per frame. The loop is on gsap.ticker and skipped while the section is off screen. The canvas pixel ratio is capped at 1.5 (1.25 on touch), which the soft light does not need more than.

To buy back frames on low-end hardware, set data-shaft="0" first (it removes the beam's reads and the dust), then lower data-dpr to 1.

Also in your download: the full source, worked examples, the events and programmatic API, and the class reference.

£7