Houdini,
Behind the CSS
Rhiana Heath
GIDS Oct 2020
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7069021/wizard-1454385_640.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7761797/readingeggs.jpeg)
Software Developer
Blake eLearning
What is CSS Houdini?
The objective of the CSS-TAG Houdini Task Force (CSS Houdini) is to jointly develop features that explain the “magic” of Styling and Layout on the web.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7738388/Screen_Shot_2020-09-18_at_4.45.30_pm.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7738390/Screen_Shot_2020-09-18_at_4.45.48_pm.png)
CSS Houdini: Backgrounds
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7738437/Screen_Shot_2020-09-18_at_5.01.33_pm.png)
CSS Houdini:
Backgrounds
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7738439/Screen_Shot_2020-09-18_at_5.01.37_pm.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7738440/Screen_Shot_2020-09-18_at_5.02.49_pm.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7738421/Screen_Shot_2020-09-18_at_4.58.08_pm.png)
CSS Houdini:
Borders
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7738426/Screen_Shot_2020-09-18_at_4.50.55_pm.png)
CSS Houdini:
Masks
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/5175050/profile_3.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7585852/Screen_Shot_2020-07-26_at_9.37.40_am.png)
New Button!
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7585858/Screen_Shot_2020-07-26_at_9.43.12_am.png)
What Can we do?
- Background image
- Extra download
- Not very responsive
- CSS hacks
- Extra DOM elements not needed
- Hard to read and maintain
CSS Hack example 1
.triangle-hack {
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #000;
}
CSS Hack example 2
.clippy-hack {
clip-path: polygon(
10% 0,
90% 0,
100% 10%,
100% 90%,
90% 100%,
10% 100%,
0 90%,
0 10%
);
}
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7738463/Screen_Shot_2020-09-18_at_5.07.42_pm.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7068964/ms_paint.jpg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/6551418/CSS3_logo_and_wordmark.svg.png)
+
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7069021/wizard-1454385_640.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/6551426/javascript-logo-E967E87D74-seeklogo.com_.png)
=
PaInt API:
What can you use it on?
background: paint(magic-bg);
border: paint(magic-border);
mask-image: paint(magic-mask);
How do you set this up?
<script>
CSS.paintWorklet.addModule('/magic-bg.js');
</script>
How do you set this up?
registerPaint('magic-bg', class {
static get inputProperties() {
return [
'--bg-colour',
];
}
paint(ctx, geom, properties) {
...
}
});
Wait what's this?
background: paint(magic-bg);
--bg-colour: #000000;
CSS Variable
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/6398070/Internet_Explorer_10_11_logo.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/5174867/symbol-2480164_640.png)
Progressive enhancement
/* Fallback for older browsers */
background: #000000;
@supports (background: paint(id)) {
background: paint(magic-bg);
--bg-colour: #000000;
}
Where does it go?
registerPaint('magic-bg', class {
static get inputProperties() {
return [
'--bg-colour',
];
}
paint(ctx, geom, properties) {
...
}
});
How do we access it?
registerPaint('magic-bg', class {
static get inputProperties() {
return [
'--bg-colour',
];
}
paint(ctx, geom, properties) {
const bgColour = properties.get('--bg-colour')
.toString();
}
});
What are those other ones?
paint(ctx, geom, properties) {
const bgColour = properties.get('--bg-colour')
.toString();
const x = geom.width;
const y = geom.height;
}
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7068999/math-27670_640.png)
Geometry
What are those other ones?
paint(ctx, geom, properties) {
const bgColour = properties.get('--bg-colour')
.toString();
const x = geom.width;
const y = geom.height;
ctx.fillStyle = bgColour;
this.drawShape(ctx, geom);
ctx.fill();
}
Context
DEMO TIME!
Pros
- Faster
- More deliberate
- More control
- New things not possible before
Cons
- Few learning resources
- Low browser support
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/6398078/chrome_logo.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/5174876/symbol-2480163_640.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7585830/edge.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7585831/opera.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/5174876/symbol-2480163_640.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/5174876/symbol-2480163_640.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/6398067/firefox-logo.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/6398076/safari_PNG33.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/5174867/symbol-2480164_640.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/5174867/symbol-2480164_640.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/295750/images/7586208/cropped-accessibility_wizard_rhiana_copy.png)