How to Set Up Canvas UI in React + Vite: WebGL Components That Make Framer Motion Feel Boring

TL;DR — Canvas UI layers WebGL shader effects over real HTML in React. Use it for one or two hero moments per page, lazy-loaded and off for reduced motion. Keep Framer Motion for layout and micro-interactions, because shaders everywhere cost battery, GPU contexts and bundle size.

Canvas UI is a React WebGL component library from DavidHDev, who also wrote React Bits. Your markup stays as real HTML and GPU shader effects sit on top of it. If you've shipped a dozen landing pages with the same Framer Motion fade-and-slide, canvas-ui react components are the quickest way to get something that looks different without writing GLSL yourself. This guide covers the canvas ui vite setup, wiring three components, and the performance cost compared with pure Framer Motion.

Short version: it's great for one or two hero moments per page, and a problem if you sprinkle it everywhere.

  1. Scaffold a Vite + React + TypeScript project and confirm it runs.
  2. Install Canvas UI and its peer dependencies with the command in the repo README.
  3. Add a shader background behind your hero and keep the headline as plain HTML.
  4. Wrap an image card and a call-to-action button with WebGL effects.
  5. Lazy-load every WebGL component and respect prefers-reduced-motion.
  6. Measure the result in a production build before you ship it.

What is Canvas UI and how is it different from Framer Motion?

Canvas UI draws shader effects on a WebGL canvas that sits over or behind real DOM elements. Framer Motion animates the DOM itself with transforms and opacity. They work on different layers and cost different things.

Framer Motion (now Motion): a declarative animation library that interpolates CSS properties on DOM nodes. Most of that work runs on the compositor thread if you stick to transform and opacity.

WebGL overlay component: a component that keeps text, links and buttons in the DOM for accessibility and SEO, and draws pixel-level effects (noise, distortion, liquid, glow) on a GPU-backed canvas lined up with that element.

That second model is the point. Your headline can still be selected, indexed and read by a screen reader, and the shader is only decoration. Framer Motion moves things beautifully, but it can't ripple an image like water or run a fluid simulation behind your hero. Canvas UI fills that gap.

Step 1: Scaffold the Vite project

Start from a clean Vite template. If you want the full opinionated stack with Biome, Vitest and a router, follow our guide to setting up React without Create React App first, then come back.

npm create vite@latest canvas-ui-demo -- --template react-ts
cd canvas-ui-demo
npm install
npm run dev

Step 2: Install Canvas UI

Install the library and its peer dependencies with the exact command from the repo README. The package name and the peers are the parts most likely to change between releases.

After the install, open node_modules and check what came with it. WebGL libraries often pull in a rendering runtime as a peer, and that runtime is your real bundle cost, not the component code. I spent longer than I'd like to admit chasing a "duplicate React" warning that turned out to be a peer version mismatch. Pin your versions, run npm ls react, and move on.

Step 3: Wire three components

Every Canvas UI component follows the same pattern: real content as children, the effect as a wrapper or sibling, and everything client-only. The component names below follow the library's style. Copy the exact names and props from the docs for the version you installed.

Start with a reduced-motion hook and a lazy boundary. You'll want both whichever components you use.

// src/hooks/usePrefersReducedMotion.ts
import { useSyncExternalStore } from 'react';

const query = '(prefers-reduced-motion: reduce)';

export function usePrefersReducedMotion() {
  return useSyncExternalStore(
    (cb) => {
      const mql = window.matchMedia(query);
      mql.addEventListener('change', cb);
      return () => mql.removeEventListener('change', cb);
    },
    () => window.matchMedia(query).matches,
    () => true,
  );
}
// src/components/Effects.tsx
import { lazy, Suspense, type ReactNode } from 'react';
import { usePrefersReducedMotion } from '../hooks/usePrefersReducedMotion';

const HeroShader = lazy(() => import('./effects/HeroShader'));

export function HeroBackdrop({ children }: { children: ReactNode }) {
  const reduced = usePrefersReducedMotion();
  return (
    <section className="hero">
      {!reduced && (
        <Suspense fallback={null}>
          <HeroShader />
        </Suspense>
      )}
      <div className="hero-content">{children}</div>
    </section>
  );
}

Give each Canvas UI component its own file under src/components/effects/ so Vite splits it into a separate chunk. These are the three I'd use on a typical marketing page:

  • Hero shader background: an animated noise or gradient field behind the headline. Position the canvas absolutely with pointer-events: none so clicks reach the real buttons.
  • Distortion image card: wraps an <img> and ripples it on hover. Keep the alt text on the real image element, not on a canvas texture.
  • Glow or liquid button: wraps a real <button>, so focus rings and keyboard handling stay native.
/* src/index.css */
.hero { position: relative; isolation: isolate; min-height: 80vh; }
.hero canvas { position: absolute; inset: 0; z-index: -1; pointer-events: none; }
.hero-content { position: relative; }

The docs don't explain the z-index setup. If your button suddenly stops receiving clicks, the canvas is on top of it. It always is.

Is Canvas UI slower than Framer Motion?

Yes. Each WebGL effect runs a shader on the GPU every frame and keeps a render loop alive. Framer Motion's transform and opacity animations are cheap compositor work that goes idle when nothing moves.

The costs that actually bite:

  • WebGL context limits: browsers cap the number of active contexts, and Chrome starts dropping the oldest at around 16. Ten shader cards in a grid is how you end up with a blank tile and a console warning.
  • Battery and heat: a full-viewport shader will warm up a mid-range Android phone. Pause rendering when the element scrolls out of view, using an IntersectionObserver.
  • Bundle weight: Framer Motion's core is small and tree-shakes well, while a WebGL runtime adds a meaningful chunk on top. Lazy-loading keeps it off the critical path, which matters more than the raw size.
  • First paint: your LCP element is still HTML text, so a lazy shader doesn't hurt LCP. It can hurt INP if the shader compiles on the main thread during an interaction, so compile on mount, not on hover.

Don't guess at any of this. Run npm run build && npm run preview, record a Performance trace with the CPU throttled, and watch frame times while you scroll. For ongoing checks, DebugBear tracks Core Web Vitals on every deploy, so you'll catch the week someone adds a fourth shader to the pricing page.

chrome devtools performance trace
chrome devtools performance trace

When should you use Canvas UI instead of Framer Motion?

Use Canvas UI for one or two signature moments per page, such as a hero or a product showcase. Keep Framer Motion for layout, page transitions and micro-interactions.

The two don't really compete. They're different tools. My rules:

  • Use Canvas UI on landing pages, portfolios, launch pages and product showcases, where the visuals are the product.
  • Skip it in dashboards, admin tools, forms, data tables and anything users look at for hours. Nobody wants a liquid shader behind an invoice list.
  • Never treat it as a Framer Motion alternative for layout animation, shared element transitions or gesture-driven UI. It doesn't do that, and it shouldn't.

If you like owning your component source, the approach from our shadcn CLI and Tailwind v4 workflow guide works here too: keep the effect files in your repo, tune the shader uniforms, and delete what you don't use.

The verdict

Canvas UI is the most fun React animation library of 2026, and the easiest one to overuse. Install it, put one shader behind your hero, lazy-load it, turn it off for reduced motion, and pause it off-screen. Deploy to Vercel or another host with good edge caching so the extra chunk arrives quickly. Keep Framer Motion for everything that moves the layout. Two effects per page is a design choice. Ten is a performance bug.

FAQs

Does Canvas UI work with Next.js App Router?

Yes, but every WebGL component has to be a client component. Add 'use client' to the effect files and load them with next/dynamic and ssr: false so the server never tries to render a canvas.

Can I use Canvas UI and Framer Motion together?

Yes, and you should. Use Framer Motion to animate the HTML content, such as the headline entrance and layout shifts, and Canvas UI for the shader layer underneath. They work on different elements, so they don't conflict.

Is Canvas UI accessible?

Mostly, because text, links and buttons stay in the DOM. You still need to turn effects off for users with prefers-reduced-motion, and keep alt text on real image elements rather than canvas textures.

Why is my Canvas UI component showing a blank canvas?

Usually there are too many WebGL contexts on the page, or the canvas has zero height. Check the console for a context-lost warning, run fewer effects at once, and give the parent element explicit dimensions.

Does Canvas UI hurt SEO?

No, as long as your content is real HTML, which is how the library is designed. Crawlers index the text and ignore the canvas.

H
Hiten

Senior frontend engineer and architect: 17 years shipping complex web platforms, plus Android and iOS apps for clients. More at hiten.dev