Interactive Demos
Live examples of <canvas-text>. Each section shows the markup alongside the rendered canvas. The building blocks come first; the real-world demos at the end are embedded live — type, pick, and download right in the frame.
Basic Text Rendering
Use compose="text-only" to render a single rich-text layer from the element's default slot. No layer pipeline overhead.
Live Demo
Hello , world !
Source
<canvas-text width="500" height="120" compose="text-only">
<p style="padding: 20px 24px; font-size: 28px; margin: 0;">
<strong>Hello</strong>, <em>world</em>!
</p>
</canvas-text>
Layered Composition
Combine slot="background" with slot="text-1" and slot="text-2" to composite text over an image — classic meme layout.
Live Demo
TOP TEXT
BOTTOM TEXT
Source
<canvas-text width="500" height="500">
<img slot="background" src="./test/fixtures/red-square.png"
crossorigin="anonymous" alt="Red background">
<div slot="text-1"
style="text-align:center; font-size:52px; font-weight:bold;
color:white; -webkit-text-stroke:2px black;
padding-top:24px;">
TOP TEXT
</div>
<div slot="text-2"
style="text-align:center; font-size:52px; font-weight:bold;
color:white; -webkit-text-stroke:2px black;
padding-top:400px;">
BOTTOM TEXT
</div>
</canvas-text>
Use padding-top for vertical placement of bottom text — position:absolute is not supported by render-tag. See CSS support for the full list.
Background Z-Stacking
slot="background-N" stacks image layers by integer N. Higher N paints on top. Text at the same N renders above its background peer.
Live Demo
z=3 text
Source
<canvas-text width="400" height="400">
<!-- z=1: full red background -->
<img slot="background-1" src="./test/fixtures/red-square.png"
crossorigin="anonymous" alt="Red background at z=1">
<!-- z=2: blue square overlaps red -->
<img slot="background-2" src="./test/fixtures/blue-square.png"
crossorigin="anonymous" alt="Blue square at z=2"
style="width:200px; height:200px;">
<!-- z=3 text: renders above both backgrounds -->
<div slot="text-3"
style="text-align:center; font-size:32px; font-weight:bold;
color:white; -webkit-text-stroke:1px black;
padding-top:160px;">
z=3 text
</div>
</canvas-text>
Theme Inherit
theme="inherit" (default) copies CSS tokens from the host element into each text layer. theme="none" uses render-tag's defaults only.
Live Demo
theme="inherit" — picks up surrounding color & font
theme="none" — render-tag defaults
Source
<!-- Wrap canvas-text in a styled ancestor -->
<div style="color: steelblue; font-size: 28px;
font-weight: 600; font-family: Georgia, serif;">
<!-- theme="inherit": canvas picks up steelblue + Georgia -->
<canvas-text width="320" height="100"
theme="inherit" compose="text-only">
<div style="padding: 16px 20px;">Theme: inherit</div>
</canvas-text>
<!-- theme="none": render-tag defaults regardless of host style -->
<canvas-text width="320" height="100"
theme="none" compose="text-only">
<div style="padding: 16px 20px;">Theme: none</div>
</canvas-text>
</div>
Allowlisted properties: color, font-family, font-size, font-weight, font-style, line-height, letter-spacing, text-align, background-color. See Theme Bridge API .
Export to Image
toBlob() returns a Promise<Blob>; toDataURL() returns a base64 string synchronously. Both reflect the last completed render.
Live Demo
Export me as PNG or JPEG!
Download PNG
Download JPEG
Source
<canvas-text id="export-demo" width="500" height="160" compose="text-only">
<div style="padding: 32px; font-size: 32px; font-weight: bold;
text-align: center; color: #0969da;">
Export me as PNG or JPEG!
</div>
</canvas-text>
<button id="btn-png">Download PNG</button>
<button id="btn-jpeg">Download JPEG</button>
<script type="module">
const el = document.getElementById('export-demo');
async function download(type, ext) {
const blob = await el.toBlob(type);
const url = URL.createObjectURL(blob);
const a = Object.assign(document.createElement('a'), {
href: url, download: `canvas-text-export.${ext}`
});
a.click();
URL.revokeObjectURL(url);
}
document.getElementById('btn-png').addEventListener('click',
() => download('image/png', 'png'));
document.getElementById('btn-jpeg').addEventListener('click',
() => download('image/jpeg', 'jpg'));
</script>
Accessibility
The slotted HTML is visually hidden but AT-readable. The canvas is aria-hidden="true". Set alt for a concise label.
Live Demo
Hello from canvas-text !
How it works
When alt is set the canvas receives aria-label="A friendly hello message" and the slotted fallback is suppressed so AT reads the alt once, not both. Without alt, the slotted children are the AT label — the canvas is aria-hidden and the visually-hidden light DOM is consumed directly.
Visually-hidden DOM snippet (inspect to verify)
<canvas-text alt="A friendly hello message">
<!-- slotted children stay in light DOM, hidden via clip-path -->
<p style="...">Hello from <strong>canvas-text</strong>!</p>
<!-- canvas is aria-hidden, gets aria-label from alt -->
<canvas aria-hidden="true" aria-label="A friendly hello message"></canvas>
</canvas-text>
Source
<canvas-text width="500" height="120" compose="text-only"
alt="A friendly hello message">
<p style="padding: 20px 24px; font-size: 28px; margin: 0;">
Hello from <strong>canvas-text</strong>!
</p>
</canvas-text>
Reactive Updates
Slot and attribute mutations trigger an automatic coalesced re-render. Type in the box or swap the background — the canvas updates without any manual render() call.
Live Demo
Caption text
Background
Red square
Blue square
None (transparent)
Hello, canvas-text!
Source
<input id="dynamic-text" type="text" value="Hello, canvas-text!">
<select id="dynamic-bg">
<option value="red">Red square</option>
<option value="blue">Blue square</option>
<option value="none">None</option>
</select>
<canvas-text id="dynamic-demo" width="500" height="200">
<img id="dynamic-bg-img" slot="background"
src="./test/fixtures/red-square.png" crossorigin="anonymous" alt="">
<div id="dynamic-text-layer" slot="text-1"
style="padding: 60px 32px; font-size: 36px; font-weight: bold;
text-align: center; color: white; -webkit-text-stroke: 1px black;">
Hello, canvas-text!
</div>
</canvas-text>
<script type="module">
const textInput = document.getElementById('dynamic-text');
const bgSelect = document.getElementById('dynamic-bg');
const bgImg = document.getElementById('dynamic-bg-img');
const textLayer = document.getElementById('dynamic-text-layer');
textInput.addEventListener('input', () => {
textLayer.textContent = textInput.value;
});
bgSelect.addEventListener('change', () => {
const fixtures = './test/fixtures/';
if (bgSelect.value === 'none') {
bgImg.removeAttribute('src');
} else {
bgImg.src = fixtures + bgSelect.value + '-square.png';
}
});
</script>
Meme generator
preset="meme" applies Impact-style type, a black stroke, and top/bottom placement. Edit the captions and download the PNG.
Source
<canvas-text preset="meme" width="500" height="500">
<img slot="background" src="cat.jpg" fit="cover" alt="">
<span slot="text-1">WHEN THE CODE</span>
<span slot="text-2">COMPILES FIRST TRY</span>
</canvas-text>
Open standalone ↗
User badge / profile card
preset="badge" centers an avatar, stacks name and title, and lays out the remaining image-N layers in a row.
Source
<canvas-text preset="badge" width="320" height="320">
<img slot="image-1" src="avatar.png" width="96" height="96" alt="">
<span slot="text-1">Prof Powell</span>
<span slot="text-2">LEVEL 42 · WEB WIZARD</span>
<img slot="image-2" src="b1.png" width="44" height="44" alt="">
<img slot="image-3" src="b2.png" width="44" height="44" alt="">
</canvas-text>
Open standalone ↗
Game banner builder
preset="banner" places the player name up top and arranges the badge row along the bottom. Pick badges from the tray to recompose live.
Source
<canvas-text preset="banner" width="480" height="270">
<img slot="background" src="banner.jpg" fit="cover" alt="">
<span slot="text-1">ProfPowell</span>
<img slot="image-1" src="a.png" width="56" height="56" alt="">
<img slot="image-2" src="b.png" width="56" height="56" alt="">
<img slot="image-3" src="c.png" width="56" height="56" alt="">
</canvas-text>
Open standalone ↗
OG / social share card
No preset — just placement attributes. place="center-left" with offset-x/offset-y positions the title and subtitle over a photo.
Source
<canvas-text width="600" height="315">
<img slot="background" src="hero.jpg" fit="cover" alt="">
<div slot="text-1" place="center-left" offset-x="40" offset-y="-20">Shipping canvas-text 0.2</div>
<div slot="text-2" place="center-left" offset-x="40" offset-y="40">Placement, presets & fonts</div>
</canvas-text>
Open standalone ↗
Caption / figure flattener
preset="caption" flattens a semantic <figure> + <figcaption> into one image with a full-width caption band. The band color is the figcaption's own background.
Source
<canvas-text preset="caption" width="500" height="333">
<figure>
<img src="photo.jpg" alt="">
<figcaption style="background:rgba(0,0,0,.55);color:#fff;padding:10px">
A captioned figure, flattened to one image
</figcaption>
</figure>
</canvas-text>
Open standalone ↗