Firefox 161, released on 24 November 2026, added support for the CSS Typed Object Model (Typed OM). According to the Firefox 161 release notes for developers, scripts can now read and write CSS values as typed JavaScript objects instead of strings, through Element.computedStyleMap() and HTMLElement.attributeStyleMap. Chrome has supported Typed OM since version 66 and Safari since 16.4, so the core API now works in all three major browser engines.

If you’ve ever written el.style.width = (parseFloat(getComputedStyle(el).width) + 10) + 'px', this API is for you. This tutorial covers the parts you’ll use most, with examples you can paste into the console. We ran the snippets in Chrome 156; the comments show the results we got.

Strings vs typed values

With the classic CSSOM, every value is a string:

const box = document.querySelector('.box');

box.style.opacity = 0.5;                  // number turned into the string "0.5"
console.log(getComputedStyle(box).width); // "320px", a string you must parse

With Typed OM, values are objects that carry a number and a unit:

const width = box.computedStyleMap().get('width');
console.log(width.value, width.unit); // 320 "px"

No parseFloat, no string concatenation, and no bugs from forgetting the unit.

Feature detection

Firefox users on older versions, and older Safari versions, won’t have it, so check first:

const hasTypedOM =
  typeof CSS !== 'undefined' &&
  typeof CSS.px === 'function' &&
  'attributeStyleMap' in HTMLElement.prototype;

if (!hasTypedOM) {
  // fall back to element.style and getComputedStyle()
}

Writing inline styles with attributeStyleMap

attributeStyleMap is the typed version of element.style. It’s a map of the element’s inline styles:

box.attributeStyleMap.set('padding-left', CSS.px(24));
box.attributeStyleMap.set('margin-top', CSS.rem(1));
box.attributeStyleMap.set('opacity', 0.8);  // plain numbers are fine for unitless properties

console.log(box.attributeStyleMap.get('padding-left').toString()); // "24px"
console.log(box.attributeStyleMap.has('opacity'));                  // true

box.attributeStyleMap.delete('margin-top');

Stick to longhand properties when you set typed values. In our Chrome test, set('padding', CSS.px(24)) and set('padding-inline', CSS.px(24)) threw “Invalid type for property”, while padding-left worked. Support for individual properties also varies: rotate with CSS.deg() was rejected in Chrome, while transform accepted a string.

The CSS.* factory functions create CSSUnitValue objects: CSS.px(), CSS.em(), CSS.rem(), CSS.percent(), CSS.vw(), CSS.deg(), CSS.s(), CSS.ms(), CSS.number() and many more.

Invalid values throw instead of failing silently. With element.style, a typo is simply ignored. With Typed OM you get an exception:

try {
  box.attributeStyleMap.set('width', CSS.deg(45)); // an angle is not a valid width
} catch (err) {
  console.error('Invalid value:', err.name); // TypeError
}

Reading computed styles with computedStyleMap()

computedStyleMap() is the typed version of getComputedStyle():

const styles = box.computedStyleMap();

const fontSize = styles.get('font-size');
console.log(fontSize.value, fontSize.unit); // e.g. 16 "px"

const display = styles.get('display');
console.log(display.constructor.name, display.value); // CSSKeywordValue "block"

Keywords come back as CSSKeywordValue objects with a .value string. Values that Typed OM doesn’t model in detail come back as a generic CSSStyleValue, and you can always call .toString() on any value.

Math without string building

Numeric values have arithmetic methods: add(), sub(), mul(), div(), min() and max(). When units match, the result is a simple value:

const a = CSS.px(10).add(CSS.px(5));
console.log(a.toString()); // "15px"

When units differ, you get a math expression that the browser resolves at layout time, just like calc():

const mixed = CSS.vw(50).sub(CSS.px(16));
console.log(mixed.constructor.name); // CSSMathSum
console.log(mixed.toString());       // "calc(50vw + -16px)"

box.attributeStyleMap.set('width', mixed);

Notice that subtraction is stored as adding a negated value, which is why the string reads + -16px. One caveat from testing: Chrome rejected math values that contained a percentage for width (for example CSS.percent(50).sub(CSS.px(16))), even though the same expression with vw worked. Test percentage math in every browser you support, or keep using a plain calc() string through element.style for those cases.

Absolute units can be converted with to():

console.log(CSS.in(1).to('px').toString()); // "96px"
console.log(CSS.s(1.5).to('ms').toString()); // "1500ms"

Parsing strings into typed values

If a value comes from user input or a config file, parse it:

const value = CSSStyleValue.parse('margin-top', '2rem');
console.log(value.value, value.unit); // 2 "rem"

A practical example: a drag-to-resize panel

Here is a small, real use case. The panel’s width is read as a number, updated by the pointer movement, clamped, and written back. There’s no string parsing anywhere:

<div class="panel" id="panel">
  <div class="handle" id="handle" aria-label="Resize panel"></div>
</div>

<style>
  .panel { position: relative; width: 320px; min-height: 200px; background: #f3f4f6; }
  .handle { position: absolute; top: 0; right: -4px; width: 8px; height: 100%; cursor: ew-resize; }
</style>
const panel = document.getElementById('panel');
const handle = document.getElementById('handle');

handle.addEventListener('pointerdown', (event) => {
  handle.setPointerCapture(event.pointerId);
  const startX = event.clientX;
  const startWidth = panel.computedStyleMap().get('width').value; // number, in px

  const onMove = (e) => {
    const next = Math.min(640, Math.max(200, startWidth + (e.clientX - startX)));
    panel.attributeStyleMap.set('width', CSS.px(next));
  };

  handle.addEventListener('pointermove', onMove);
  handle.addEventListener(
    'pointerup',
    () => handle.removeEventListener('pointermove', onMove),
    { once: true }
  );
});

The same pattern works for sliders, zoom controls and any animation loop that updates a numeric style every frame. Skipping string parsing and serializing on each frame keeps that code simpler.

Custom properties work too

You can read and write CSS custom properties through the same maps:

document.documentElement.attributeStyleMap.set('--sidebar-width', '280px');

const raw = document.documentElement.computedStyleMap().get('--sidebar-width');
console.log(raw.constructor.name); // CSSUnparsedValue
console.log(raw.toString());       // "280px"

An unregistered custom property has no known type, so pass a string (Chrome rejected CSS.px(280) here), and you get back a CSSUnparsedValue. Registering the property with @property and a syntax such as '<length>' tells the browser its type.

Limits to know about

  • Colors aren’t typed yet. MDN’s Firefox 161 notes point out that the color value interfaces, such as CSSColorValue and CSSRGB, aren’t supported in Firefox or any other browser. Read colors with .toString().
  • Not every property accepts typed values everywhere. Shorthands and some newer properties may only accept strings, and complex values like grid-template-areas often come back as a generic CSSStyleValue. Wrap set() calls in try/catch while you test.
  • Older browsers. Users on Firefox 160 or earlier, or Safari before 16.4, won’t have the API, so keep a fallback path for anything critical.

Takeaway

With Firefox 161, CSS Typed OM works in Chrome, Safari and Firefox. Use attributeStyleMap and CSS.px() instead of string-building inline styles, computedStyleMap() instead of parsing getComputedStyle(), and the built-in math methods instead of hand-written calc() strings. Feature-detect for now, and see the MDN CSS Typed OM guide for the full reference.