Canvas UI puts WebGL shaders over real, interactive HTML
By Flavio
Updated
Tagged: JavaScript
Canvas UI uses the HTML-in-Canvas API to combine real DOM content with WebGL shaders, without giving up links, forms, or accessibility.
Canvas UI is a component library that applies canvas and WebGL effects to real DOM content. It can make HTML ripple, refract, burn, or dissolve into particles without turning your interface into a dead image.
For years, web developers had to choose between the DOM and <canvas>. The DOM gives you text, links, forms, accessibility, find-in-page, translation, and everything else that makes the web work. Canvas gives you pixels. Once something becomes pixels, you can bend it, blur it, break it into particles, run it through a shader, or make it move like water, but the browser no longer sees a heading, a button, or an input. It just sees a rectangle of color.
Canvas UI tries to remove that tradeoff. David Haz, the creator of React Bits, launched Canvas UI as an HTML-in-canvas component library that feeds your live DOM straight into WebGL effects.
Text can ripple like water, a glass lens can refract a real page, and content can break into particles around the pointer, while the markup underneath stays ordinary HTML. Links still click, text stays selectable, and forms keep working.
What is Canvas UI?
Canvas UI is a collection of 35 creative visual components for websites, including liquid, glass, fire, cloth, rain, a VHS effect, particle reveals, ripples, glitches, and 3D objects.

Some of the effects are pure WebGL or Three.js, so they work in modern browsers today. Others rely on a new browser feature called HTML-in-Canvas: they take live HTML, turn its rendered output into a texture, and process that texture with WebGL.
The library isn’t trying to replace HTML with a canvas UI framework. You still write normal markup and components, and Canvas UI wraps a visual layer around them. For example, here’s how the React version of the Liquid component wraps existing content:
import { Liquid } from '@/components/canvasui/Liquid'
export default function Hero() {
return (
<Liquid rainbow style={{ height: 480 }}>
<h1>Build something memorable</h1>
<button>Get started</button>
</Liquid>
)
}
The heading and button don’t turn into fake canvas controls. They stay real DOM elements, and Liquid just changes how they’re painted.
Here’s the Liquid demo after dragging across the image:

Why putting HTML inside canvas is a big deal
The canvas API is an immediate-mode drawing API. You tell it to draw a rectangle, some text, or an image, and it updates the pixels and forgets whatever produced them. Take a text call like this:
context.fillText('Hello', 20, 40)
Once that runs, the canvas doesn’t hold a text node with the word Hello. It only holds pixels shaped like those letters. The browser can’t select them, find-in-page won’t match them, a screen reader has no idea they form a heading, and a translation extension can’t swap them out.
If you build a canvas-heavy app, you either have to rebuild all of those features yourself or keep a hidden DOM tree synced beside the canvas. That’s why the DOM and canvas usually sit in separate layers: normal controls in HTML, a canvas placed behind or in front of them, and glue code trying to keep both in sync.
That setup works fine for backgrounds and decorative particles, but it gets painful fast when the effect needs to distort the interface itself. Before HTML-in-Canvas, developers reached for screenshots, DOM-to-image libraries, SVG <foreignObject>, or duplicated layouts. Each approach hits walls with live form controls, videos, web fonts, cross-origin content, or anything that updates often.
Since the browser already knows how to paint the DOM, HTML-in-Canvas exposes that work directly to canvas.
How HTML-in-Canvas works
HTML-in-Canvas is a browser API that shipped in Chrome 157. You opt in by adding content="drawable" to the canvas and drawable to each element you want to draw:
<canvas content="drawable">
<div id="content" drawable>
<h1>Hello</h1>
<button>Click me</button>
</div>
</canvas>
Normally, elements inside <canvas> are just fallback content that browsers show when canvas isn’t available. With content="drawable", the browser lays out that HTML as live content tied to the canvas and keeps the elements in the accessibility tree.
During the origin trial, the canvas attribute was called layoutsubtree and there was no drawable attribute. Chrome 155 renamed it, so you’ll still run into the old name in older demos.
From there, the API adds methods for drawing a DOM element into a 2D canvas, a WebGL texture, or a WebGPU texture. Here’s what the 2D version looks like:
canvas.onpaint = () => {
context.reset()
context.drawElementImage(content, 0, 0)
}
Whenever the content changes, the browser fires a paint event. Typing into an input, selecting text, or updating a style can all trigger a repaint. In WebGL the equivalent method is texElementSubImage2D(), and in WebGPU it’s drawElementImageToTexture().
The last piece is keeping positions in sync. If a shader bends or shifts a button, the browser has to know where that button ended up on screen so the clickable area matches what you see. In a 2D canvas the browser handles that for you because drawElementImage() moves the element to wherever it was drawn. With WebGL and WebGPU, you pass the position manually using canvas.updateElementGeometry().
How Canvas UI builds an effect
Let’s look at how the Liquid component is put together. The full source is available in the Canvas UI repository. It’s a big file because it holds the component, WebGL setup, fluid simulation, shaders, event handling, and cleanup all in one place.
First, Canvas UI creates a source canvas that wraps the HTML. It sets content="drawable" and drawable in browsers that support them, falling back to layoutsubtree on older Chrome builds.
When the browser asks for a repaint, the component calls drawElementImage():
canvas.onpaint = () => {
context.reset()
context.drawElementImage(content, 0, 0)
contentDirty = true
}
Next, it uploads that source canvas into a WebGL texture:
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
gl.RGBA,
gl.UNSIGNED_BYTE,
source
)
Once the rendered interface is in a texture, the shader can sample it like any other image. Liquid also keeps separate textures for velocity, dye, pressure, curl, and divergence. Moving the pointer injects force into the simulation, and the display shader uses that simulated flow to offset where it reads from the content texture.
Put plainly, your pointer stirs a small fluid simulation, and the fluid shifts which part of the interface each pixel pulls from.
The output renders into a second canvas layered on top of the content. That output canvas has pointer-events: none, so clicks, drags, and selections pass straight through to the real HTML underneath while the browser keeps the layout and canvas in sync.
The content is still part of the web
The visual demos get all the attention, but keeping the real DOM underneath is what makes this practical. When you draw an entire interface by hand on a canvas, you give up a huge list of built-in browser features, and rebuilding them yourself is brutal.
With HTML-in-Canvas, the browser still sees the underlying elements, so you keep:
- text selection, copy, and paste
- native form controls
- accessibility tools and screen readers
- find-in-page
- browser translation and extensions
- browser zoom and autofill
- DevTools inspection
- indexing by search engines and AI agents
A crawler doesn’t need computer vision to figure out a button painted inside a 3D scene, because it’s still a real button in the DOM. You can push the visuals much further without hiding the content from browsers, assistive tools, or search engines.
You can see this clearly in the Glass component, where a circular lens refracts and magnifies the live content under the pointer:

Browser support is the big limitation
HTML-in-Canvas isn’t something you can assume every visitor has. It’s on by default starting in Chrome 157, while Safari and Firefox don’t support it yet.
When I first wrote this post it was an origin trial in Chrome 148 through 150. If you’re on a Chrome version older than 157, you still need an origin trial token on your domain or this flag enabled:
chrome://flags/#canvas-draw-element
Canvas UI also keeps Android on the fallback for now after reports of crashes there. Under the hood, it checks for browser support with feature detection:
function supportsHtmlInCanvas() {
const canvas = document.createElement('canvas')
const context = canvas.getContext('2d')
return Boolean(
context &&
typeof context.drawElementImage === 'function' &&
typeof canvas.requestPaint === 'function'
)
}
When the API isn’t there, the content renders as ordinary HTML. Standalone WebGL overlays keep working, while effects that depend on a live page texture drop that layer gracefully without breaking the page.
How Canvas UI limits GPU work
A collection of full-screen WebGL effects can turn into a laptop fan controller very quickly. The Shatter demo, for example, lifts parts of the page into distorted glass fragments around the pointer:

Canvas UI can’t make GPU work free, and some of its components are intentionally heavy. Particle Object, for example, can load a 3D model and rebuild it out of thousands of particles.
To keep the cost down, the Liquid component uses IntersectionObserver to pause its animation loop once the output scrolls out of view, and it stops rendering after the fluid settles and nothing is changing. It also respects prefers-reduced-motion by skipping pointer-driven movement when a visitor asks for less motion. When the component unmounts, it cancels the animation frame, disconnects observers, removes event listeners, deletes its textures and shader programs, and releases its buffers.
Those details are what make a component usable in a real app, even if they don’t make a good launch video.
Still, test on the devices your visitors use. A fluid simulation running on a desktop GPU feels very different from the same simulation on an older phone. My advice is to pick one strong effect instead of stacking six competing ones on the same page.
You copy the code into your project
Canvas UI follows the shadcn distribution model. Instead of adding one large package as a permanent dependency, you use the shadcn CLI to copy a component’s source right into your project:
npx shadcn@latest add @canvas-ui/liquid-react
The component lands in components/canvasui/. There are versions for React, Solid, Preact, Vue, Svelte, and dependency-free vanilla TypeScript, all sharing the same options for each effect.
Every component also ships as a WebGPU build with the same options. You install it by adding -webgpu to the component name:
npx shadcn@latest add @canvas-ui/liquid-react-webgpu
I like this model for creative components. Shader code almost always needs tweaks for your specific project, whether that’s a different color model, a lower simulation resolution, a different pointer response, or a lighter version for mobile. When the source lives in your repo, editing it is straightforward and you don’t have to fight an abstraction trying to cover every possible use case.
The tradeoff is that updates are on you. Re-running the install command can pull down a newer version, but you have to check how it fits with your local edits.
The project is licensed under MIT with the Commons Clause. You can use the components in personal and commercial projects, but you can’t resell or redistribute the library itself as a competing product.
It is also designed for coding agents
Canvas UI exposes its components through a shadcn-compatible registry, so an AI coding agent using the shadcn MCP server can browse the components, read their metadata, and install one by name. For example, you can ask it something like this:
Add the Canvas UI liquid effect to my hero section
From there, the agent finds the right registry entry and brings the source into your project.
Documentation used to be written only for humans. Now a good library also needs structured metadata, predictable files, installable source, and enough context for an agent to pick the right component. The Canvas UI MCP setup doesn’t need a separate custom server either, since it builds on the existing shadcn MCP server and registry protocol, which makes the library much easier to discover and plug into existing tools.
Where I would use Canvas UI
Canvas UI fits best when the visual effect is part of the message. Good places to use it include:
- a product launch page
- a portfolio
- a game or interactive story
- a hero section
- an art project
- a focused product demo
- an experimental interface
Be careful about spreading it across a whole documentation site, a dashboard, a checkout flow, or a long article. Motion draws attention, so you don’t want everything on the page moving at once.
There’s also a practical constraint: the full HTML-in-Canvas experience only runs in Chrome 157 and later, so a production design still has to look good without it. The best setup treats it as an extra visual layer for supported browsers while unsupported browsers get a clean, normal page.
What HTML-in-Canvas could enable
The components are fun. Open the Canvas UI gallery, move your cursor around, and it’s hard not to try every demo.
The DOM handles meaning and interaction well, while Canvas and WebGL give you far more visual freedom. Until now, the browser kept a wall between them, and HTML-in-Canvas changes that by letting the DOM feed into the graphics pipeline.
With that in place, a 3D game terminal could contain a real text input, diagram editors could attach accessible HTML controls to objects in the scene, and design tools could place normal, searchable text on a WebGL surface. Other interfaces could change visually without hiding their meaning from a screen reader or an AI agent.
Canvas UI is an early, practical look at that idea. Only Chrome runs the full effects today, but I still like the direction of making the web visually richer without losing the HTML underneath.
Want me to talk about your product? You can sponsor this site.
Related posts about js: