Video as a material for editable text
The large text below is two editable HTML elements in one canvas. A shader takes their picture as one texture and a video frame as a second. Type in the text, select it, and pick an effect. Under the code listing, the same fill is built three times with CSS and no shader.
Show the code text texture, video texture, one shader, and the 2D and CSS versions
- The markup. Two
contenteditableelements in adrawablechild of the canvas. The video is outside the canvas. - The CSS. White text on a clear background. The font size follows the canvas width, so the text wraps again when the canvas changes size.
- WebGL 2: two textures.
texElementSubImage2D()for the text andtexImage2D(video)for the frame, in thepainthandler. - The fragment shader. Six effects. Coverage is the smallest of the three colour channels.
- 2D canvas: no shader.
drawElementImage(), then the video withsource-inorsource-out. - WebGPU.
drawElementImageToTexture()for the text andcopyExternalImageToTexture()for the frame. - When to paint. The video isn't a canvas child, so the page asks for a paint for each video frame.
- The CSS for the three versions with no shader.
- The markup for the three versions with no shader.
The fill without a shader
Each box below plays the same video. The first two can be edited.
BLEND
mix-blend-mode: multiply, over a <video>.drawable canvas child, drawn by one drawElementImage() call. The blend is in the element's picture.<video> with clip-path: url(#…) to an SVG <clipPath> that holds <text>. SVG text doesn't wrap and can't be edited.How it works
- The text element fills the canvas. Its font size is a fraction of
canvas.clientWidth, so a narrower canvas wraps the text again. The browser does the wrapping. - The text is styled white on a clear background. In the shader, coverage is the smallest of the red, green and blue channels of the premultiplied text texture. A white glyph pixel gives 1, a clear pixel gives 0, and an antialiased edge gives its alpha.
- A pixel that has alpha but isn't white isn't a glyph. That's the selection highlight, the caret, the focus ring or a colour emoji. The shader draws those over the effect in their own colour at 60% strength.
- The video isn't a child of the canvas.
texImage2D(video),copyExternalImageToTexture()ordrawImage(video)reads its current frame.requestVideoFrameCallback()asks for one paint per video frame. Typing, the caret and selection changes raisepaintwith no request. - WebGL and WebGPU don't tell the browser where the element is drawn. The page calls
updateElementGeometry()with an identity matrix after each resize, so taps and the caret go to the text as it is laid out. - The 2D route has no shader. It draws the text, then draws the video with
globalCompositeOperation = 'source-in'(fill) or'source-out'(punch). It builds those two effects only.
Live checks
Each check builds its own small canvas in a corner of the window. The text above isn't touched. One check selects text in its own fixture, which clears a selection made elsewhere on the page for a moment and then restores it.
| Result | Experiment | Detail |
|---|
Findings
From Chromium 157 headless with software rendering and software video decoding, 2026-11-21. The rows above say what your browser does.
- Works: editable DOM text as a shader input next to a video frame. The text stays editable, selectable and wrapped by the browser in every route. Six effects are built. A pixel inside a glyph differed from the video pixel by 1 of 255.
- Works with CSS and no canvas: fill and punch.
mix-blend-mode: multiplyorscreenon text over a video gives both, with editable HTML text. An SVG<clipPath>or<mask>gives the fill for SVG text and shapes only. - Works: the CSS blend inside a drawable element. When the video and the blended text are both inside the drawn element, the blend is in its picture.
- Works in 2D only: the blend mode of the drawn element itself.
drawElementImage()appliedmix-blend-mode: multiplyon the element against the pixels the canvas already held.texElementSubImage2D()gave the unblended picture, so a shader doesn't see the blend. - Works: three ways to fill text with video in a 2D canvas.
source-in,globalCompositeOperation = 'multiply', and the element's own blend mode. Mean difference from the shader fill: 1.5 of 255. - Limit:
background-clip: textcan't use a video. Chromium has noelement()and no-webkit-canvas()image.paint()parses, but a paint worklet draws CSS image values only (inferred from its interface, not measured). - Needs the canvas: displace, chrome, mosaic and weight. Each one reads the text's pixels and the video's pixels at different places and computes a new pixel. CSS blending and clipping combine the two pictures at the same place only. The 2D route can't build them without a per-pixel loop in script.
- Selection and caret are in the text texture. A route that uses alpha as coverage (2D
source-in) turns the selection highlight and the caret into video. The shader keys on white, so it draws glyphs with the effect and the highlight and caret in their own colours. - Timing: a video beside the canvas raises no paint. 0 paints a second, against 30 with the video inside the drawn element.
requestVideoFrameCallback()supplies them. With the page idle, the frame fromtexImage2D(video)was the frame the callback reported in 26 of 28 paints. With a second canvas drawing in software at the same time it was 2 to 6 frames newer. - Limit: a WebGL canvas needs
updateElementGeometry(). Before the call,elementFromPoint()at a drawn letter returned the canvas and no caret position. After it, the paragraph and the right offset. - WebGPU: built, compared off screen only. On the software adapter the six WGSL effects matched WebGL exactly. That adapter refused
copyExternalImageToTexture(video)andimportExternalTexture(video), so the frame went through a 2D canvas. - Not verified here: the WebGPU route on screen and a video frame straight into a GPU texture, a hardware-decoded frame through
texImage2D(video)on Android, touch selection handles and the on-screen keyboard on the drawn text, and the frame rate on a phone.