CSSNumericValue: toSum() method

Note: This feature is available in Web Workers.

The toSum() method of the CSSNumericValue interface converts the object's value to a CSSMathSum of CSSUnitValues using only the specified units, if possible. If called with no units, it simplifies the value into a minimal sum of CSSUnitValues instead.

Syntax

js
toSum()
toSum(unit1)
toSum(unit1, unit2)
toSum(unit1, unit2, /* …, */ unitN)

Parameters

unit1, …, unitN Optional

The units to convert to.

Return value

A CSSMathSum.

Exceptions

SyntaxError DOMException

Thrown if any of unit1, …, unitN is not a valid unit identifier.

TypeError

Thrown if:

Examples

undefined

Basic usage

js
let v = CSS.px("23").add(CSS.percent("4")).add(CSS.cm("3")).add(CSS.in("9"));
v.toString(); // => "calc(23px + 4% + 3cm + 9in)"
v.toSum("px", "percent").toString(); // => "calc(1000.39px + 4%)"

Specifications