Lesson 44 of 50
cssCSS Houdini – The Paint API
10 mins
Course progress88%
What you'll learn
Keep this idea in mind as you work through the lesson.
Lesson 44 of 50
css10 mins
Keep this idea in mind as you work through the lesson.
Houdini opens the browser for developer‑defined rendering.
if ('paintWorklet' in CSS) {
CSS.paintWorklet.addModule('bg-paint.js');
}
bg-paint.js
registerPaint('bg', class {
static get inputProperties(){ return ['--color']; }
paint(ctx, size, props){
ctx.fillStyle = props.get('--color').toString();
ctx.fillRect(0,0,size.width,size.height);
}
});
.box { background-image:paint(bg); --color:#ff6600; }