Typed OM and Houdini
Definition and purpose
CSS Typed OM exposes values as typed objects rather than only serialized strings. Houdini is a family of specifications that exposes selected CSS mechanisms; support varies by API.
Typed length with fallback
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { width: 100px; } </style> </head> <body> <div id="a">Typed width</div> <output id="report"></output> <button type="button" id="change">Grow 20px</button> <script> const a=document.querySelector("#a");document.querySelector("#change").onclick=()=>{if(a.attributeStyleMap&&window.CSS&&CSS.px&&a.computedStyleMap){const w=a.computedStyleMap().get("width");try{a.attributeStyleMap.set("width",w.to("px").add(CSS.px(20)));}catch(e){a.style.width=(parseFloat(getComputedStyle(a).width)+20)+"px";}}else{a.style.width=(parseFloat(getComputedStyle(a).width)+20)+"px";}document.querySelector("#report").textContent=getComputedStyle(a).width;}; </script> </body></html>Click Grow to add 20px using typed arithmetic or the pixel-string fallback.
Syntax and mental model
computedStyleMap() exposes computed typed values; attributeStyleMap changes inline declarations. CSS.px(20) creates a length; compatible CSSNumericValue objects support conversions and arithmetic. Percentages cannot always convert to pixels without context. Detect each required API and handle unsupported values, falling back to string CSSOM for known resolved pixel lengths. Paint Worklet uses a module and secure context where supported; it is separate from Typed OM, and not needed for this example.
Read a typed value
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { width: 140px; } </style> </head> <body> <div id="a">Width</div> <output id="report"></output> <script> const a=document.querySelector("#a");document.querySelector("#report").textContent=a.computedStyleMap?String(a.computedStyleMap().get("width")):getComputedStyle(a).width; </script> </body></html>The report shows a serialized width; inspect the typed object separately in DevTools.
Common mistakes
Do not assume every typed value is a CSSUnitValue or every supported method accepts every property. Feature-detect and catch invalid conversions; the fallback here assumes a definite px width.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Layout, paint, raster and compositing. Next lesson: CSS-related events.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Typed OM and Houdini — knowledge check
Five questions on typed om and houdini.
What does CSS.px(20) produce?
Which API changes inline typed declarations?
Can a percentage always convert directly to pixels?
Does Typed OM support imply Paint Worklet support?
What is safe for a known resolved px width when Typed OM is unavailable?