Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

paint() — image produced by a Paint Worklet

`paint()` refers to a registered JavaScript painter that produces an `<image>` responsive to a box’s size and computed style.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

paint( <ident> [, <declaration-value>]? )

paint() refers to a registered JavaScript painter that produces an <image> responsive to a box’s size and computed style.

In this Chromium, paint(cktis-grid) reports support false, CSS.paintWorklet is absent, and the computed image is none. The fallback color therefore remains visible as pixel 0,128,0,255; the example does not pretend that a paint worklet ran.

Grammar: paint( <ident> [, <declaration-value>]? ).

The first argument is an identifier matching the name passed to registerPaint(); its module is loaded with CSS.paintWorklet.addModule(). Optional arguments are checked at draw time against declared inputArguments; an unregistered name, wrong count, or wrong type produces an invalid image. A painter can declare observed properties and receives the output size, but its result must not replace accessible content; in cursor, the function is always an invalid image and the next fallback is used.

Examples

const probe=document.createElement('div');probe.style.cssText='width:8px;height:8px;background-color:rgb(0 128 0);background-image:paint(cktis-grid)';document.body.append(probe);
const supported=CSS.supports('background-image','paint(cktis-grid)');
const worklet=Boolean(CSS.paintWorklet);
const computed=getComputedStyle(probe).backgroundImage;
const svg='<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><foreignObject width="8" height="8"><div xmlns="http://www.w3.org/1999/xhtml" style="width:8px;height:8px;background-color:rgb(0 128 0);background-image:paint(cktis-grid)"></div></foreignObject></svg>';
const image=new Image();image.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(svg);await image.decode();const canvas=document.createElement('canvas');canvas.width=canvas.height=8;const context=canvas.getContext('2d');context.drawImage(image,0,0);const pixel=[...context.getImageData(4,4,1,1).data].join(',');
console.log('supported='+supported+'; paint-worklet='+worklet+'; computed-image='+computed+'; fallback-pixel='+pixel);

Result

supported=false; paint-worklet=false; computed-image=none; fallback-pixel=0,128,0,255

`paint()` refers to a registered JavaScript painter that produces an `<image>` responsive to a box’s size and computed style.

Sources