docs.rodeo

MDN Web Docs mirror

CSS Typed Object Model API

{{DefaultAPISidebar("CSS Typed Object Model API")}} 

The CSS Typed Object Model API simplifies CSS property manipulation by exposing CSS values as typed JavaScript objects rather than strings. This not only simplifies CSS manipulation, but also lessens the negative impact on performance as compared to {{domxref('HTMLElement.style')}} .

Generally, CSS values can be read and written in JavaScript as strings, which can be slow and cumbersome. CSS Typed Object Model API provides interfaces to interact with underlying values, by representing them with specialized JS objects that can be manipulated and understood more easily and more reliably than string parsing and concatenation. This is easier for authors (for example, numeric values are reflected with actual JS numbers, and have unit-aware mathematical operations defined for them). It is also generally faster, as values can be directly manipulated and then cheaply translated back into underlying values without having to both build and parse strings of CSS.

CSS Typed OM both allows for the performant manipulation of values assigned to CSS properties while enabling maintainable code that is both more understandable and easier to write.

Interfaces

CSSStyleValue

The {{domxref('CSSStyleValue')}}  interface of the CSS Typed Object Model API is the base class of all CSS values accessible through the Typed OM API. An instance of this class may be used anywhere a string is expected.

StylePropertyMap

The {{domxref('StylePropertyMap')}}  interface of the CSS Typed Object Model API provides a representation of a CSS declaration block that is an alternative to CSSStyleDeclaration.

CSSUnparsedValue

The {{domxref('CSSUnparsedValue')}}  interface of the CSS Typed Object Model API represents property values that reference custom properties. It consists of a list of string fragments and variable references.

CSSKeywordValue Serialization

The {{domxref('CSSKeywordValue')}}  interface of the CSS Typed Object Model API creates an object to represent CSS keywords and other identifiers.

CSSStyleValue Interfaces

{{domxref('CSSStyleValue')}}  is the base class through which all CSS values are expressed. Subclasses include:

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN