Supported frameworks
Shaders runs in any web project that renders in a browser with WebGPU, with components for React, Vue, Svelte and Solid and a JavaScript API for everything else.
When your agent installs a shader, it writes it for the framework your project already uses. The setups below matter when you want to check support, or when a project can't run npm install, like a Framer site or a WordPress theme.
Choosing the import for your framework
The shaders package has one entry point per UI library. Every entry point has the same components and props:
| Library | Import from | Works with |
|---|---|---|
| React | shaders/react | React 18 and 19 |
| Vue | shaders/vue | Vue 3.5 and later |
| Svelte | shaders/svelte | Svelte 5 |
| Solid | shaders/solid | Solid 1.8 and later |
| No library | shaders/js | Any page that runs JavaScript |
Install the package with your package manager:
npm install shaders
A meta-framework uses the entry point of the library it's built on, so a Next.js app imports from shaders/react and a Nuxt app from shaders/vue. Plain JavaScript uses createShader from shaders/js, which takes a <canvas> and the same components as a list. The quickstart shows the same effect written in all five.
Using a meta-framework
npx shaders connect reads your package.json, recognizes the frameworks below, and writes components where that framework expects them:
| Framework | Library | Components land in | Server rendering |
|---|---|---|---|
| Next.js | React | src/components/shaders | Add 'use client' to the shader's file |
| Remix, React Router | React | app/components/shaders | Works as is |
| TanStack Start, Gatsby | React | src/components/shaders | Works as is |
| Nuxt | Vue | components/shaders | Wrap the shader in <ClientOnly> |
| SvelteKit | Svelte | src/lib/components/shaders | Works as is |
| SolidStart | Solid | src/components/shaders | Load the shader with clientOnly |
| Astro | Any of the four | src/components/shaders | Use a client directive (below) |
| Vite | Any of the four | src/components/shaders | No server rendering |
In a project without a src/ directory the folder moves up a level, as Working with the CLI describes. You can change it with outDir in shaders.config.ts.
WebGPU only exists in the browser, so a shader can't draw during a server render. Where the table says "works as is", <Shader> renders an empty element on the server and starts the GPU once it mounts in the browser. Server rendering has the setup for each framework in full, including how to keep the Shaders bundle off the server entirely.
Using Astro
Astro renders components from React, Vue, Svelte and Solid as islands: parts of the page that load JavaScript in the browser. Add the integration for the library you want if your project doesn't have one yet:
npx astro add react
Then render the installed shader with client:only, which skips the server render and mounts it in the browser:
---
// src/pages/index.astro
import HeroShader from '../components/shaders/HeroShader'
---
<section class="hero">
<HeroShader client:only="react" />
<h1>Your content</h1>
</section>
Pass the library's name to client:only ("react", "vue", "svelte" or "solid"). Without a client directive, Astro sends the component as static HTML with no JavaScript, and the canvas never draws.
An Astro project with no UI integration can use the JavaScript API from a <script> tag. Astro bundles the script and runs it only in the browser:
<canvas id="hero" style="width: 100%; height: 480px"></canvas>
<script>
import { createShader } from 'shaders/js'
const canvas = document.getElementById('hero') as HTMLCanvasElement
createShader(canvas, {
components: [
{ type: 'LinearGradient', props: { colorA: '#0f172a', colorB: '#7c3aed' } },
{ type: 'CursorTrail', props: {} },
],
})
</script>
npx shaders connect asks which library to use when it can't find one, so in this setup ask your agent for the JavaScript version of a shader instead.
Adding a shader to any web page
Sites without a build step, like a WordPress theme, a Shopify theme or a Webflow page, can load Shaders from a CDN. The package includes a single-file build of the JavaScript API for this:
<canvas id="hero" style="display: block; width: 100%; height: 480px"></canvas>
<script type="module">
import { createShader } from 'https://cdn.jsdelivr.net/npm/shaders@5/dist/js/bundle.js'
createShader(document.getElementById('hero'), {
components: [
{ type: 'LinearGradient', props: { colorA: '#0f172a', colorB: '#7c3aed' } },
{ type: 'CursorTrail', props: {} },
],
})
</script>
The canvas needs a size from CSS. Without one it has nothing to fill and draws at the browser's default of 300×150px.
shaders@5 loads the newest 5.x release, so you get fixes without editing the page. To lock the version, pin it in full, as in shaders@5.0.0. The file is about 3MB before compression, and the browser caches it after the first visit.
Put the snippet wherever your platform accepts custom HTML: a Custom HTML block in WordPress, a Custom Liquid section in Shopify, or a Code Embed element in Webflow. Some platforms only allow custom scripts on paid plans, so check yours first.
To get a shader you designed in this form, ask your agent:
Adding a custom component to the page
The same file includes defineShader and wgsl, so a custom component works on a plain page too. Define it in the script and pass it to createShader as the third argument, so its name resolves in components:
<canvas id="hero" style="display: block; width: 100%; height: 480px"></canvas>
<script type="module">
import { createShader, defineShader, wgsl, transformColor, transformPosition } from 'https://cdn.jsdelivr.net/npm/shaders@5/dist/js/bundle.js'
const Halo = defineShader({
name: 'Halo',
props: {
color: { default: '#ffd166', transform: transformColor },
center: { default: { x: 0.5, y: 0.5 }, transform: transformPosition },
radius: { default: 0.6 },
},
paint: wgsl`
let d = length((uv - center) * vec2f(aspect, 1.0)) / radius;
return vec4f(color.rgb, 1.0 - smoothstep(0.8, 1.0, d));
`,
})
createShader(document.getElementById('hero'), {
components: [
{ type: 'LinearGradient', props: { colorA: '#0f172a', colorB: '#7c3aed' } },
{ type: 'Halo', props: { radius: 0.4 } },
],
}, { components: [Halo] })
</script>
If you move the component into a separate script or file, import from exactly the same address in both. shaders@5 in one and shaders@5.0.0 in another load two copies of the engine, and the component won't render.
Using Framer
A Framer site can run a shader as a code component: a React component written in a code file inside your Framer project. Framer can't install npm packages, so the file imports a single-file build of shaders/react from a CDN. Framer supplies React itself.
To add one, open the Assets panel in Framer, create a new code file, and replace its contents with the shader:
import { Shader, LinearGradient, CursorTrail } from 'https://cdn.jsdelivr.net/npm/shaders@5/dist/react/bundle.js'
/**
* @framerSupportedLayoutWidth any-prefer-fixed
* @framerSupportedLayoutHeight any-prefer-fixed
* @framerIntrinsicWidth 1280
* @framerIntrinsicHeight 720
*/
export default function HeroShader({ style }) {
return (
<Shader style={style}>
<LinearGradient colorA="#0f172a" colorB="#7c3aed" />
<CursorTrail />
</Shader>
)
}
Drag the component from the Assets panel onto your canvas and size it like any other layer.
Framer passes every code component a style with the size you give it on the canvas. Pass it to <Shader>, or the canvas won't fill the layer. The comment block above the function sets how the layer can be sized and its size when you first drop it in. Here it starts at 1280×720 with a fixed size, like an image.
Adding controls to the Framer panel
To change a shader's colors or settings from Framer's properties panel, turn those values into props and describe them with addPropertyControls:
import { Shader, LinearGradient, CursorTrail } from 'https://cdn.jsdelivr.net/npm/shaders@5/dist/react/bundle.js'
import { addPropertyControls, ControlType } from 'framer'
/**
* @framerSupportedLayoutWidth any-prefer-fixed
* @framerSupportedLayoutHeight any-prefer-fixed
* @framerIntrinsicWidth 1280
* @framerIntrinsicHeight 720
*/
export default function HeroShader({ style, startColor, endColor, angle, trailSize }) {
return (
<Shader style={style}>
<LinearGradient colorA={startColor} colorB={endColor} angle={angle} />
<CursorTrail radius={trailSize} />
</Shader>
)
}
addPropertyControls(HeroShader, {
startColor: { type: ControlType.Color, title: 'Start color', defaultValue: '#0f172a' },
endColor: { type: ControlType.Color, title: 'End color', defaultValue: '#7c3aed' },
angle: { type: ControlType.Number, title: 'Angle', min: 0, max: 360, step: 1, defaultValue: 0 },
trailSize: { type: ControlType.Number, title: 'Trail size', min: 0.5, max: 2, step: 0.1, defaultValue: 0.5 },
})
Each key in addPropertyControls is a prop of your component, and each shows up as a field when the layer is selected. Take min, max and the default from the prop's table on its component page, so the panel can't send a value the component doesn't accept. Use these control types:
- Colors:
ControlType.Color, for any color prop. - Numbers:
ControlType.Numberwithmin,maxandstep, for any range prop. - Images:
ControlType.Image, which hands your component an image URL. Pass it to theurlprop ofImageTexture, with a fallback (url={image ?? 'https://…'}), since an image control has no default value. - Options:
ControlType.Enumwithoptions, for props that take one of a few strings, like a blend mode.
Your agent can write the file for you. Ask for the shader as a Framer code component and name the settings you want in the panel:
Adding a custom component in Framer
The bundle also includes defineShader and wgsl, so a shader that uses a custom component fits in the same code file. Define the component above your Framer component and mount it with <CustomShader>. Its props can take values from the properties panel like any other:
import { Shader, CustomShader, LinearGradient, defineShader, wgsl, transformColor, transformPosition } from 'https://cdn.jsdelivr.net/npm/shaders@5/dist/react/bundle.js'
import { addPropertyControls, ControlType } from 'framer'
const Halo = defineShader({
name: 'Halo',
props: {
color: { default: '#ffd166', transform: transformColor },
center: { default: { x: 0.5, y: 0.5 }, transform: transformPosition },
radius: { default: 0.6 },
},
paint: wgsl`
let d = length((uv - center) * vec2f(aspect, 1.0)) / radius;
return vec4f(color.rgb, 1.0 - smoothstep(0.8, 1.0, d));
`,
})
/**
* @framerSupportedLayoutWidth any-prefer-fixed
* @framerSupportedLayoutHeight any-prefer-fixed
* @framerIntrinsicWidth 1280
* @framerIntrinsicHeight 720
*/
export default function HeroShader({ style, haloColor, haloSize }) {
return (
<Shader style={style}>
<LinearGradient colorA="#0f172a" colorB="#7c3aed" />
<CustomShader src={Halo} color={haloColor} radius={haloSize} />
</Shader>
)
}
addPropertyControls(HeroShader, {
haloColor: { type: ControlType.Color, title: 'Halo color', defaultValue: '#ffd166' },
haloSize: { type: ControlType.Number, title: 'Halo size', min: 0.1, max: 1, step: 0.05, defaultValue: 0.6 },
})
Define the component outside the function, so it's built once rather than on every render.
To share one custom component between several shaders, you can move it into its own code file. Every file then has to import exactly the same address: shaders@5 in one and shaders@5.0.0 in another load two copies of the engine, and the component won't render.
Checking browser support
Shaders needs WebGPU, which current Chrome, Edge and Safari support. Where a browser can't provide a GPU device, the canvas stays transparent and the rest of the page works as normal. This is the same in every framework above.
To show something else in those browsers, check for support before you mount, or listen for the failure. Hooks and events covers both.