1. How to use?
if ('paintWorklet' in CSS) {
CSS.paintWorklet.addModule('paint.js');
}
// paint.js
registerPaint('transparent-grid', class {
paint(context, size) {
...
}
})
.container {
background-image: paint(transparent-grid);
}
Notes: An important caveat is that the Paint API only works over https
or on localhost
. If you’re developing locally, http-server makes it super easy to view your pages on localhost
.