Favorites

paint() CSS Function

paint()
CSS FunctionThis function is supported in some modern browsers, but not all.
Updated 21st November 2026

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.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

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

<div class="wrap">
<h1>CSS paint() examples</h1>
<div class="grid">
<div class="card">
<div class="box"></div>
<div class="label">background-image: paint(dots)</div>
</div>
<div class="card">
<div class="box pink"></div>
<div class="label">--dot-color: #db2777; --dot-size: 24</div>
</div>
</div>
<script>
if ('paintWorklet' in CSS) {
const code = `registerPaint('dots', class {
static get inputProperties() { return ['--dot-color', '--dot-size']; }
paint(ctx, size, props) {
const color = props.get('--dot-color').toString().trim() || '#2563eb';
const step = parseFloat(props.get('--dot-size').toString()) || 14;
ctx.fillStyle = color;
for (let y = step / 2; y < size.height; y += step) {
for (let x = step / 2; x < size.width; x += step) {
ctx.beginPath();
ctx.arc(x, y, step / 4, 0, Math.PI * 2);
ctx.fill();
}
}
}
});`;
CSS.paintWorklet.addModule(URL.createObjectURL(new Blob([code], { type: 'text/javascript' })));
}
</script>
<p class="note">In browsers without the CSS Painting API, a plain gray background is shown.</p>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* paint() examples */
.box {
height: 160px;
border-radius: 12px;
--dot-color: #2563eb;
--dot-size: 14;
/* fallback when paint() or the worklet is unavailable */
background-color: #e2e8f0;
background-image: paint(dots);
}

.box.pink {
--dot-color: #db2777;
--dot-size: 24;
}
Open in editor

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.

This function is supported in some modern browsers, but not all.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.