LIGHT. MATH. YOUR NEXT BUILD.
Build an interactive shader background in React
Build a Prism hero with a real WebGL background, a palette switcher, a pause button and a static color fallback. This walkthrough uses the files in a normal Striktly download. Your React project does not need Striktly account keys, membership code or a hosted renderer service.
1. Download a configured Prism kit
Open Prism and choose your starting colors and motion. Select Take the code, sign in to a verified account and download the kit. Complete membership access is free during the current launch offer; membership details describe the current plans.
Start with Prism without uploaded imagery for this example. Keep the downloaded LICENSE and any applicable notices with the project. There is no public Striktly npm package to install, and this tutorial does not replace the normal download flow.
In an existing React app, copy these files into a local folder:
src/
App.jsx
hero.css
shader-kit/
ShaderBackground.jsx
shader-background.js
config.json
LICENSE
The exported component uses React hooks and runs in a browser. For server-rendered Next.js applications, follow the client-component guide as well. Leave the downloaded component and runtime together so their relative import continues to work.
2. Add the hero component
Replace src/App.jsx with the following. The downloaded configuration preserves your chosen starting look. The example scopes pointer input to the hero and caps rendering at 700,000 pixels and 30 FPS. These are workload limits, not a performance promise.
import { useEffect, useMemo, useRef, useState } from 'react';
import ShaderBackground from './shader-kit/ShaderBackground.jsx';
import { PRISM_STAGE_CSS } from './shader-kit/shader-background.js';
import downloadedConfig from './shader-kit/config.json';
import './hero.css';
const palettes = [
{ name: 'Your palette', colors: downloadedConfig.colors },
{ name: 'Afterglow', colors: ['#1b0b3b', '#ed72d6', '#628fff'] },
{ name: 'Arctic', colors: ['#070a0c', '#6d8799', '#d7e9f3'] },
];
export default function App() {
const section = useRef(null);
const [palette, setPalette] = useState(0);
const [userPaused, setUserPaused] = useState(false);
// Start paused until browser preferences and visibility are known.
const [policy, setPolicy] = useState({ reduced: true, visible: false });
useEffect(() => {
const motion = window.matchMedia('(prefers-reduced-motion: reduce)');
let onScreen = !('IntersectionObserver' in window);
const sync = () => setPolicy({
reduced: motion.matches,
visible: onScreen && !document.hidden,
});
const observer = 'IntersectionObserver' in window
? new IntersectionObserver(([entry]) => {
onScreen = entry.isIntersecting;
sync();
})
: null;
if (section.current) observer?.observe(section.current);
motion.addEventListener('change', sync);
document.addEventListener('visibilitychange', sync);
sync();
return () => {
observer?.disconnect();
motion.removeEventListener('change', sync);
document.removeEventListener('visibilitychange', sync);
};
}, []);
const paused = userPaused || policy.reduced || !policy.visible;
const config = useMemo(() => ({
...downloadedConfig,
effect: 'prism',
colors: palettes[palette].colors,
maxPixels: 700000,
maxFPS: 30,
globalPointer: false,
paused,
// Freeze cursor deformation too, not only the animation clock.
interaction: paused ? 0 : (downloadedConfig.interaction ?? 1),
}), [palette, paused]);
return (
<main className="tutorial-page">
<style>{PRISM_STAGE_CSS}</style>
<section ref={section} aria-labelledby="hero-title">
<ShaderBackground config={config} className="ambient-prism-stage prism-hero">
<div className="prism-copy">
<p className="prism-eyebrow">YOUR NEXT IDEA / A LITTLE ATMOSPHERE</p>
<h1 id="hero-title">Make room for a different feeling.</h1>
<p>Light in the background. Your idea in the foreground.</p>
<a className="prism-action" href="#details">Explore the details</a>
</div>
<div className="prism-controls" aria-label="Background controls">
<label htmlFor="hero-palette">Palette</label>
<select id="hero-palette" value={palette}
onChange={event => setPalette(Number(event.target.value))}>
{palettes.map((item, index) => (
<option key={item.name} value={index}>{item.name}</option>
))}
</select>
<button type="button" disabled={policy.reduced}
aria-pressed={userPaused || policy.reduced}
onClick={() => setUserPaused(value => !value)}>
{policy.reduced ? 'Motion reduced' : userPaused ? 'Resume motion' : 'Pause motion'}
</button>
</div>
</ShaderBackground>
</section>
<section className="prism-details" id="details">
<h2>Give the idea the foreground.</h2>
<p>The moving surface is decorative. The heading, link and controls are real HTML.</p>
</section>
</main>
);
}
The component updates settings through React state instead of recreating a renderer on each palette change. The downloaded ShaderBackground creates its renderer in an effect and calls destroy() on unmount. This walkthrough also disconnects its visibility observer and preference listeners when removed.
3. Add layout and a fallback
Create src/hero.css:
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: #090617; color: #fff; font-family: system-ui, sans-serif; }
.prism-hero {
min-height: 80svh;
display: grid;
align-content: center;
gap: 36px;
padding: clamp(24px, 6vw, 90px);
background: linear-gradient(135deg, #090617, #241144 65%, #442054);
}
.prism-copy, .prism-controls { position: relative; z-index: 3; }
.prism-copy { max-width: 760px; }
.prism-eyebrow { font-size: 11px; letter-spacing: .12em; }
.prism-copy h1 { font-size: clamp(42px, 7vw, 96px); line-height: 1.02; letter-spacing: -.06em; margin: 24px 0; }
.prism-copy p { max-width: 48ch; line-height: 1.7; }
.prism-action { display: inline-flex; padding: 14px 20px; margin-top: 18px; background: #baff33; color: #101510; font-weight: 650; text-decoration: none; }
.prism-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.prism-controls label { font-size: 13px; }
.prism-controls select, .prism-controls button {
min-height: 44px; padding: 10px 14px; border: 1px solid #b7a6db;
background: #160d2d; color: #fff; font: inherit;
}
.prism-controls button { cursor: pointer; }
.prism-controls button:disabled { cursor: default; color: #c9bedf; }
.prism-action:focus-visible, .prism-controls :focus-visible { outline: 3px solid #baff33; outline-offset: 5px; }
.prism-details { padding: 70px clamp(24px, 6vw, 90px); min-height: 65svh; }
.prism-details h2 { font-size: clamp(30px, 4vw, 52px); letter-spacing: -.04em; }
.prism-details p { max-width: 65ch; color: #d5c9e9; line-height: 1.8; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
The gradient provides a useful background while WebGL initializes or is unavailable. Keep ambient-prism-stage and PRISM_STAGE_CSS for Prism; they preserve its stage arrangement. When adapting this tutorial to another shader, use that kit's own stage styles and component. Changing an effect ID does not add a renderer to a specialized download.
4. Run and check the behavior
Render App through your existing React entry point and start the app using your project's normal development command. Keep React Strict Mode enabled while testing: its extra development setup and cleanup cycle helps reveal missing cleanup.
- Move the pointer over the hero. It should affect the shader without taking over the controls.
- Choose a palette. Colors should change without adding another canvas.
- Click Pause motion. Time and pointer deformation should stop. Changing palettes must not resume it.
- Scroll the hero offscreen or hide the tab. Returning should resume only if you did not pause it yourself.
- Enable reduced motion in your browser or OS. The scene should pause and the button should read Motion reduced.
- Navigate away and return in your app. Check that the previous renderer was destroyed and only one canvas remains.
- Test on an actual phone as well as a responsive viewport. Check text contrast across frames and lower the pixel budget if the finished page is too costly.
A Lighthouse loading score does not measure sustained shader FPS or battery use. The performance guide covers pixel budgets, reduced motion and hidden-tab behavior. Do not increase rendering quality simply to chase a screenshot if the target device cannot sustain it.
Continue building
Browse animated gradient backgrounds for alternatives to Prism. For a full layout, try the landing-page starter. Use the registry guide if you prefer a reusable shadcn integration shell, or JavaScript if your project does not use React.