Lab 01: CSS Houdini

Time: 30 minutes | Level: Advanced | Docker: docker run -it --rm node:20-alpine sh

Overview

Explore CSS Houdini APIs: @property with typed syntax, animatable custom properties, CSS Typed OM simulation, the Paint API concept, and browser support status.


Step 1: @property — Registered Custom Properties

/* Unregistered: browser treats as opaque string, can't animate */
:root { --angle: 0deg; }
/* transition: --angle 1s; */  /* WON'T WORK — browser doesn't know it's an angle */

/* @property: tell the browser the TYPE */
@property --angle {
  syntax: '<angle>';
  inherits: false;
  initial-value: 0deg;
}

@property --brand-color {
  syntax: '<color>';
  inherits: true;
  initial-value: #3b82f6;
}

@property --progress {
  syntax: '<number>';
  inherits: false;
  initial-value: 0;
}

@property --gradient-stop {
  syntax: '<percentage>';
  inherits: false;
  initial-value: 0%;
}

/* Now these ARE animatable! */
.animated-gradient {
  background: conic-gradient(from var(--angle), blue, purple, blue);
  transition: --angle 1s ease;
}

.animated-gradient:hover {
  --angle: 180deg; /* smoothly interpolates! */
}

Step 2: Syntax Types Reference

💡 inherits: true means child elements inherit the value. inherits: false means each element gets its own copy — important for per-element animations.


Step 3: Animated Conic Gradient


Step 4: Per-Element Animation with inherits: false


Step 5: CSS Typed OM Concept

CSS Typed OM (computedStyleMap()) provides typed access to CSS values:


Step 6: Paint API Concept

The CSS Paint API (Houdini) lets JavaScript define custom CSS images:


Step 7: Houdini Browser Support (2024)


Step 8: Capstone — @property Syntax Generator

(First create the file:)

📸 Verified Output:


Summary

Feature
Syntax
Support

@property declaration

syntax, inherits, initial-value

Chrome/FF/Safari ✓

Animatable color

syntax: '<color>'

All modern ✓

Animatable angle

syntax: '<angle>'

All modern ✓

Per-element animation

inherits: false

All modern ✓

Typed OM

el.computedStyleMap()

Chrome ~, limited

Paint API

CSS.paintWorklet.addModule()

Chrome only ✗

CSS.px() factory

CSS.px(200)

Chrome ✓

@supports guard

@supports (background: paint(x))

Feature-detect

Last updated