Note: This feature is available in Web Workers.
The toString() method of the CSSStyleValue interface is a stringifier that returns the value formatted as a string of standard CSS text.
toString()None.
A string.
The exact serialization of the object to a string depends on how the CSSStyleValue object was obtained:
CSSStyleValue.parse(), the method returns the original string that was parsed.CSS factory function or a subclass constructor, the returned string is generated according to serialization rules specific to that subclass.Element.computedStyleMap() or HTMLElement.attributeStyleMap, the returned string follows the CSSOM serialization rules.For more information about serialization rules see When and how values are serialized in CSS value serialization.
// Parsed from a string: returns the original string
const length1 = CSSStyleValue.parse("42.0px");
length1.toString(); // "42.0px"
// Constructed directly with a CSS factory function: subclass-specific serialization
const length2 = CSS.px(42.0);
length2.toString(); // "42px"
// Read from the CSSOM: follows CSSOM serialization rules
const element = document.createElement("div");
element.style.width = "42.0px";
const length3 = element.attributeStyleMap.get("width");
length3.toString(); // "42px"