paint() CSS Function
The paint() function draws an image with a JavaScript paint worklet (CSS Painting API), usable anywhere an image is allowed. It works in Chromium browsers.
Description
The paint() CSS function draws an image using a paint worklet, a small JavaScript program registered with the CSS Painting API (part of the "Houdini" set of APIs). Instead of loading a picture file, the browser calls your worklet's paint() method whenever the element needs to be drawn, passing it a canvas-like drawing context and the element's size. The result can be used anywhere CSS accepts an <image>, such as background-image, border-image and mask-image.
The first argument is the name the worklet was registered under with registerPaint(). Any further arguments are passed to the worklet, and the worklet can also read custom properties from the element through its inputProperties list. Because the image is generated on demand, it automatically redraws when the element resizes or when one of those properties changes, which makes it ideal for patterns, decorative borders and effects that depend on the element's size.
/* JavaScript, in checkerboard.js:
registerPaint('checkerboard', class {
static get inputProperties() { return ['--size']; }
paint(ctx, size, props) { ... }
});
...and in the page:
CSS.paintWorklet.addModule('checkerboard.js'); */
.pattern {
--size: 20;
background-color: #e2e8f0; /* fallback */
background-image: paint(checkerboard);
}
paint() is supported in Chromium-based browsers only. Firefox and Safari do not support the CSS Painting API, so always provide a fallback such as a solid color or a gradient.
Syntax
paint() = paint( <ident>, <declaration-value>? )
Values
- <ident>The name of the paint worklet, as registered in JavaScript with registerPaint().
- <declaration-value>Optional. Extra comma-separated arguments passed to the worklet's paint() method.
Example
Browser Support
The following information will show you the current browser support for the CSS paint() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





