π₯ Make videos programmatically with React
docs: add HTML-in-canvas overview page
JonnyBurgereabcf37e0a7c
diff --git a/packages/core/src/HtmlInCanvas.tsx b/packages/core/src/HtmlInCanvas.tsxindex f5dfb9d412..e7b3223a43 100644--- a/packages/core/src/HtmlInCanvas.tsx+++ b/packages/core/src/HtmlInCanvas.tsx@@ -552,11 +552,11 @@ HtmlInCanvasInner.displayName = 'HtmlInCanvas';const HtmlInCanvasWrapped = wrapInSchema(HtmlInCanvasInner, htmlInCanvasSchema);export const HtmlInCanvas = Object.assign(HtmlInCanvasWrapped, {- isHtmlInCanvasSupported,+ isSupported: isHtmlInCanvasSupported,}) as React.ForwardRefExoticComponent<HtmlInCanvasProps & React.RefAttributes<HTMLCanvasElement>> & {- readonly isHtmlInCanvasSupported: typeof isHtmlInCanvasSupported;+ readonly isSupported: typeof isHtmlInCanvasSupported;};HtmlInCanvas.displayName = 'HtmlInCanvas';diff --git a/packages/docs/components/demos/HtmlInCanvasDocsVideoFallback.tsx b/packages/docs/components/demos/HtmlInCanvasDocsVideoFallback.tsxindex 37285b1811..60fc38ef0a 100644--- a/packages/docs/components/demos/HtmlInCanvasDocsVideoFallback.tsx+++ b/packages/docs/components/demos/HtmlInCanvasDocsVideoFallback.tsx@@ -3,7 +3,7 @@ import React from 'react';import {AbsoluteFill, staticFile, useVideoConfig} from 'remotion';/**- * Pre-rendered fallback when `HtmlInCanvas.isHtmlInCanvasSupported()` is false.+ * Pre-rendered fallback when `HtmlInCanvas.isSupported()` is false.* `relativeSrc` is relative to the docs site static root (e.g. `img/foo.mp4`).** Typography is sized vs. composition width so it stays legible when the Playerdiff --git a/packages/docs/components/demos/useHtmlInCanvasDocsDemoBranch.ts b/packages/docs/components/demos/useHtmlInCanvasDocsDemoBranch.tsindex 5b524b08b1..3effb6dca8 100644--- a/packages/docs/components/demos/useHtmlInCanvasDocsDemoBranch.ts+++ b/packages/docs/components/demos/useHtmlInCanvasDocsDemoBranch.ts@@ -10,9 +10,7 @@ export const useHtmlInCanvasDocsDemoBranch = (): HtmlInCanvasDocsDemoBranch => {const [branch, setBranch] = useState<HtmlInCanvasDocsDemoBranch>('pending');useEffect(() => {- setBranch(- HtmlInCanvas.isHtmlInCanvasSupported() ? 'live' : 'fallback',- );+ setBranch(HtmlInCanvas.isSupported() ? 'live' : 'fallback');}, []);return branch;diff --git a/packages/docs/docs/client-side-rendering/html-in-canvas.mdx b/packages/docs/docs/client-side-rendering/html-in-canvas.mdxindex 163a0aac42..e3aa05f54e 100644--- a/packages/docs/docs/client-side-rendering/html-in-canvas.mdx+++ b/packages/docs/docs/client-side-rendering/html-in-canvas.mdx@@ -12,7 +12,11 @@ Experimental feature - expect bugs and breaking changes at any time.# HTML-in-canvas<AvailableFrom v="4.0.447" />-On supported Chromium-based browsers, [`@remotion/web-renderer`](/docs/web-renderer) can optionally capture full frames using the experimental [HTML-in-canvas](https://github.com/WICG/html-in-canvas) APIs.+:::note+This is not the same as the [`<HtmlInCanvas>`](/docs/html-in-canvas) component for designing visuals. This page describes a [`@remotion/web-renderer`](/docs/web-renderer) option that uses HTML-in-canvas to capture full frames during client-side rendering.+:::++On supported Chromium-based browsers, [`@remotion/web-renderer`](/docs/web-renderer) can optionally capture full frames using the experimental [HTML-in-canvas](/docs/html-in-canvas) APIs.:::infoAs of April 2026, this feature requires [Chrome Canary](https://www.google.com/chrome/canary/). Regular Chrome has partial support ([`drawElementImage`](https://github.com/WICG/html-in-canvas#2-drawelementimage-and-webglwebgpu-equivalents)) but is missing `canvas.requestPaint()`, which can cause rendering issues such as frames being repeated. See [Compatibility](#compatibility) for details.diff --git a/packages/docs/docs/contributing/presentation.mdx b/packages/docs/docs/contributing/presentation.mdxindex 320bb2da6f..f38105c0cc 100644--- a/packages/docs/docs/contributing/presentation.mdx+++ b/packages/docs/docs/contributing/presentation.mdx@@ -83,7 +83,7 @@ If you want to contribute the presentations back into the `@remotion/transitions<Step>3</Step> Mind the time convention: in our shaders <code>u_time = 0</code> outputs the entering scene and <code>u_time = 1</code> outputs the exiting scene. When porting from gl-transitions, set <code>float progress = 1.0 - u_time;</code> at the top of <code>main()</code>.<br /><Step>4</Step> Handle the boundary cases inside the JS <code>draw()</code> function: when <code>prevImage</code> is <code>null</code>, force <code>time = 0</code>; when <code>nextImage</code> is <code>null</code>, force <code>time = 1</code>.<br /><Step>5</Step> Set <code>serverSideRendering</code>, <code>nodejs</code>, <code>bun</code> and <code>serverlessFunctions</code> to <code>true</code> in the <code><CompatibilityTable /></code> on your docs page β Remotion's bundled Chromium for Lambda already includes the required APIs. Set <code>firefox</code> and <code>safari</code> to <code>false</code>.<br />-<Step>6</Step> The table-of-contents preview should always render the pre-rendered fallback video β the live <code><Player></code> would crash for readers without HTML-in-canvas enabled, and a tiny TOC tile gains nothing from running the real shader. See <a href="https://github.com/remotion-dev/remotion/blob/main/packages/docs/components/transitions/zoom-blur-toc-preview.tsx"><code>zoom-blur-toc-preview.tsx</code></a> for the pattern. For the in-page <code><Demo></code>, branch on <code>HtmlInCanvas.isHtmlInCanvasSupported()</code> via the <code>useHtmlInCanvasDocsDemoBranch()</code> hook so supporting browsers see the real shader and others fall back to the video β see <a href="https://github.com/remotion-dev/remotion/blob/main/packages/docs/components/demos/ZoomBlurDemo.tsx"><code>ZoomBlurDemo.tsx</code></a>.<br />+<Step>6</Step> The table-of-contents preview should always render the pre-rendered fallback video β the live <code><Player></code> would crash for readers without HTML-in-canvas enabled, and a tiny TOC tile gains nothing from running the real shader. See <a href="https://github.com/remotion-dev/remotion/blob/main/packages/docs/components/transitions/zoom-blur-toc-preview.tsx"><code>zoom-blur-toc-preview.tsx</code></a> for the pattern. For the in-page <code><Demo></code>, branch on <code>HtmlInCanvas.isSupported()</code> via the <code>useHtmlInCanvasDocsDemoBranch()</code> hook so supporting browsers see the real shader and others fall back to the video β see <a href="https://github.com/remotion-dev/remotion/blob/main/packages/docs/components/demos/ZoomBlurDemo.tsx"><code>ZoomBlurDemo.tsx</code></a>.<br /><Step>7</Step> Render the fallback videos from a composition under <code>packages/example/src/HtmlInCanvas/</code> using <code>npx remotion render <id> --browser-executable=<path-to-Chrome-Canary> --allow-html-in-canvas</code>. Drop a high-res 1920Γ1080 file at <code>packages/docs/static/img/<name>.mp4</code> for the docs page and a low-res 540Γ280 file at <code><name>-thumb.mp4</code> for the TOC tile.<br /><Step>8</Step> Add an <code><HtmlInCanvasLabel /></code> next to the presentation name in the table-of-contents tile to flag the requirement.diff --git a/packages/docs/docs/html-in-canvas-guide.mdx b/packages/docs/docs/html-in-canvas-guide.mdxnew file mode 100644index 0000000000..edf87333c1--- /dev/null+++ b/packages/docs/docs/html-in-canvas-guide.mdx@@ -0,0 +1,132 @@+---+image: /generated/articles-docs-html-in-canvas-guide.png+id: html-in-canvas+title: HTML-in-canvas+crumb: 'Designing visuals'+---++<SuggestedPrompts prompts={['use remotion html-in-canvas best practices. create a sample composition and apply a glitch effect to it!', 'use remotion html-in-canvas best practices. make a new composition and implement a subtle CRT convex shape shader on top of a HTML element. content: terminal and remotion themed. the command and output of "npx create-video@latest --yes --blank my-video" should be animated. then "claude" should be invoked and the prompt "Add a CRT effect using HTML-in-canvas " should be shown']} />++# HTML-in-canvas<AvailableFrom v="4.0.455" />++[HTML-in-canvas](https://github.com/WICG/html-in-canvas) is an experimental browser API currently only available in Chrome Canary behind a flag.++It allows you to draw a live DOM node into a `<canvas>` and post-process it with the Canvas 2D API, WebGL or WebGPU.++## Enabling the flag in Chrome Canary++To preview HTML-in-canvas effects in the [Remotion Studio](/docs/studio), you need to use [Chrome Canary](https://www.google.com/chrome/canary/) v149 and enable a flag:++1. Install [Chrome Canary](https://www.google.com/chrome/canary/).+2. Open `chrome://flags/#canvas-draw-element`.+3. Set the `HTML-in-Canvas` flag to `Enabled` and restart.++To check at runtime whether HTML-in-canvas is supported, you can use [`HtmlInCanvas.isSupported()`](/docs/remotion/html-in-canvas#htmlincanvasissupported).++For rendering, you don't need to do anything β see [Rendering](#rendering) below.++## The `<HtmlInCanvas>` component++[`<HtmlInCanvas>`](/docs/remotion/html-in-canvas) is a convenient component which wraps it's children in a canvas and allows you to manipulate the content when the canvas is painted.++```tsx twoslash title="MyComp.tsx"+import {HtmlInCanvas, type HtmlInCanvasOnPaint} from 'remotion';++const onPaint: HtmlInCanvasOnPaint = ({canvas, element, elementImage}) => {+ const ctx = canvas.getContext('2d');+ if (!ctx) {+ throw new Error('Failed to acquire 2D context');+ }++ ctx.reset();+ ctx.filter = 'blur(8px)';+ const transform = ctx.drawElementImage(elementImage, 0, 0);+ element.style.transform = transform.toString();+};++export const MyComp: React.FC = () => {+ return (+ <HtmlInCanvas width={1280} height={720} onPaint={onPaint}>+ <div style={{fontSize: 80}}>Hello</div>+ </HtmlInCanvas>+ );+};+```++See the [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas) reference for the full API, including WebGL and WebGPU examples.++### Using the browser API directly++You can also use the browser API directly. Refer to the [working draft](https://github.com/WICG/html-in-canvas) to do so.+If you do so, you are responsible yourself for calling [`delayRender()`](/docs/delay-render) and [`clearRender()`](/docs/clear-render) to synchronize paint operations.++## Examples++Find example components in the [`remotion-dev/html-in-canvas`](https://github.com/remotion-dev/html-in-canvas) repository.++Also see the following sample prompts in our prompt gallery that you can give your coding agent:++- [Magnifying glass](https://www.remotion.dev/prompts/html-in-canvas-magnifying-glass)+- [Vintage screen effect](https://www.remotion.dev/prompts/vintage-screen-effect-html-in-canvas)+- [Glitch effect](https://www.remotion.dev/prompts/glitch-effect-html-in-canvas)++## With `@remotion/transitions`++[`@remotion/transitions`](/docs/transitions) can take advantage of HTML-in-canvas as well to blend two scenes.+See [`zoomBlur()`](/docs/transitions/presentations/zoom-blur) presentation for an example.++You can also build your own β see [Making a custom HTML-in-canvas presentation](/docs/transitions/presentations/custom-html-in-canvas).++## Limitations++HTML-in-canvas is only available in [Chrome Canary](https://www.google.com/chrome/canary/) (Chrome 149 and later) with the `chrome://flags/#canvas-draw-element` flag enabled.+The API is unstable - Chrome may change the API or even remove it in the future.++Nesting `<HtmlInCanvas>` inside another `<HtmlInCanvas>` is not supported. Chrome would only display the outer effect, so this is invalid in Remotion. It will throw an error.+If you need to combine multiple effects, try to merge them into a single `onPaint` callback.++## Rendering++From [`v4.0.455`](https://github.com/remotion-dev/remotion/releases/tag/v4.0.455), render is supported locally via [`npx remotion render`](/docs/cli/render) and Studio, on [Lambda](/docs/lambda), on [Vercel](/docs/vercel) and through [server-side rendering](/docs/ssr) APIs.++We compiled a version of Chrome Canary and made it the default, and enabled the flag for you.++If your effect uses a WebGL shader, pass [`--gl=angle`](/docs/gl-options) to make the render work:++```bash+npx remotion render --gl=angle+```++Set it as the default in [`remotion.config.ts`](/docs/config) so Studio and CLI renders pick it up as a default:++```ts twoslash title="remotion.config.ts"+import {Config} from '@remotion/cli/config';+// ---cut---+Config.setChromiumOpenGlRenderer('angle');+```++If your machine has no GPU, we recommend `gl=swangle` instead (default on Lambda).++## AI agents++Remotion publishes [Agent Skills](/docs/ai/skills) that teach AI agents like Claude Code, Codex and Cursor how to use [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas) correctly β including the [`onInit`](/docs/remotion/html-in-canvas#oninit) / [`onPaint`](/docs/remotion/html-in-canvas#onpaint) lifecycle, the [`--gl=angle` flag](#rendering) and the [no-nesting rule](#limitations).++Install them with:++```bash+npx skills add remotion-dev/skills+```++## Leveraging HTML-in-canvas for client-side rendering++Not directly related, but also leveraging the same technology is the [HTML-in-canvas option in `@remotion/web-renderer`](/docs/client-side-rendering/html-in-canvas).++When enabled, the [client-side renderer](/docs/client-side-rendering) uses HTML-in-canvas to capture full frames in the browser, which can produce more accurate output than the default DOM compositor.++This mode cannot render compositions that contain [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas) elements, because doing so would [nest HTML-in-canvas](#limitations) captures, which Chrome does not support.++## See also++- [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas)+- [HTML-in-canvas examples on GitHub](https://github.com/remotion-dev/html-in-canvas)+- [Making a custom HTML-in-canvas presentation](/docs/transitions/presentations/custom-html-in-canvas)diff --git a/packages/docs/docs/remotion/html-in-canvas.mdx b/packages/docs/docs/remotion/html-in-canvas.mdxindex 57dc8e8f46..4838779f2e 100644--- a/packages/docs/docs/remotion/html-in-canvas.mdx+++ b/packages/docs/docs/remotion/html-in-canvas.mdx@@ -8,6 +8,8 @@ crumb: 'API'This component renders its children into a `<canvas>` using the browserβs [HTML-in-canvas](https://github.com/WICG/html-in-canvas) API and allows you to draw an effect using the Canvas 2D API, WebGL or WebGPU.+For an overview, examples and how to enable the Chrome Canary flag, see the [HTML-in-canvas guide](/docs/html-in-canvas).+HTML-in-canvas is only available in Chrome 149 and later and if the `chrome://flags/#canvas-draw-element` flag is enabled.```tsx twoslash title="MyComp.tsx"@@ -22,18 +24,18 @@ export const MyComp: React.FC = () => {};```-## `HtmlInCanvas.isHtmlInCanvasSupported()`+## `HtmlInCanvas.isSupported()`Return value: _boolean_If HTML-in-canvas is not available, the component throws a fatal error.-Use `HtmlInCanvas.isHtmlInCanvasSupported()` to check if HTML-in-canvas is supported.+Use `HtmlInCanvas.isSupported()` to check if HTML-in-canvas is supported.Buggy implementations such as the one in Chrome 147 are not considered supported.```ts twoslash title="Check if HTML-in-canvas is supported"import {HtmlInCanvas} from 'remotion';-if (HtmlInCanvas.isHtmlInCanvasSupported()) {+if (HtmlInCanvas.isSupported()) {console.log('HTML-in-canvas is supported');} else {console.log('HTML-in-canvas is not supported');@@ -796,6 +798,7 @@ Only works in Chrome 149 and later with the flag enabled, as mentioned on the to## See also+- [HTML-in-canvas guide](/docs/html-in-canvas)- [HTML-in-canvas (client-side rendering)](/docs/client-side-rendering/html-in-canvas)- [`<Sequence>`](/docs/sequence)- [Source code for this component](https://github.com/remotion-dev/remotion/blob/main/packages/core/src/HtmlInCanvas.tsx)diff --git a/packages/docs/docs/transitions/presentations/custom-html-in-canvas.mdx b/packages/docs/docs/transitions/presentations/custom-html-in-canvas.mdxindex 96f2a5e101..9fca945142 100644--- a/packages/docs/docs/transitions/presentations/custom-html-in-canvas.mdx+++ b/packages/docs/docs/transitions/presentations/custom-html-in-canvas.mdx@@ -6,7 +6,7 @@ title: 'Custom HTML-in-canvas presentations'# Custom HTML-in-canvas presentations<AvailableFrom v="4.0.456" />-Build a presentation that runs the entering and exiting scenes through a shader using the [HTML-in-canvas](https://github.com/WICG/html-in-canvas) APIs.+Build a presentation that runs the entering and exiting scenes through a shader using the [HTML-in-canvas](/docs/html-in-canvas) APIs.:::warningHTML-in-canvas requires [Chrome Canary](https://www.google.com/chrome/canary/) with `chrome://flags/#canvas-draw-element` enabled in the browser.diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex 8c8548c785..5be042cc71 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -927,9 +927,10 @@ const sidebars: SidebarsConfig = {'fonts','measuring','using-randomness',- 'noise-visualization','maps','animation-math',+ 'html-in-canvas',+ 'noise-visualization','shaders','light-leaks','starburst',diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 785b00c6ba..50266fbdce 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -2069,6 +2069,15 @@ export const articles = [noAi: false,slug: 'props-resolution',},+ {+ id: 'html-in-canvas',+ title: 'HTML-in-canvas',+ relativePath: 'docs/html-in-canvas-guide.mdx',+ compId: 'articles-docs-html-in-canvas-guide',+ crumb: 'Designing visuals',+ noAi: false,+ slug: 'html-in-canvas',+ },{id: 'html5-audio',title: '<Html5Audio>',diff --git a/packages/docs/static/generated/articles-docs-html-in-canvas-guide.png b/packages/docs/static/generated/articles-docs-html-in-canvas-guide.pngnew file mode 100644index 0000000000..939f60141aBinary files /dev/null and b/packages/docs/static/generated/articles-docs-html-in-canvas-guide.png differdiff --git a/packages/docs/vercel.ts b/packages/docs/vercel.tsindex e6822990b7..14ac1767b1 100644--- a/packages/docs/vercel.ts+++ b/packages/docs/vercel.ts@@ -56,6 +56,9 @@ export const config: VercelConfig = {{permanent: false},),routes.redirect('/timeout', '/docs/timeout', {permanent: false}),+ routes.redirect('/html-in-canvas', '/docs/html-in-canvas', {+ permanent: false,+ }),routes.redirect('/acknowledgements', '/docs/acknowledgements', {permanent: false,}),diff --git a/packages/transitions/src/html-in-canvas-presentation.tsx b/packages/transitions/src/html-in-canvas-presentation.tsxindex e1fe36f3f6..e4685f1380 100644--- a/packages/transitions/src/html-in-canvas-presentation.tsx+++ b/packages/transitions/src/html-in-canvas-presentation.tsx@@ -23,7 +23,7 @@ export const HtmlInCanvasPresentation = <readonly shader: HtmlInCanvasShader<TPassedProps>;readonly _experimentalEffects?: EffectsProp;}) => {- if (!HtmlInCanvas.isHtmlInCanvasSupported()) {+ if (!HtmlInCanvas.isSupported()) {throw new Error('HTML in Canvas is not supported. Open this page in Chrome Canary with chrome://flags/#canvas-draw-element enabled.',);