CSSNumericValue: to() method

Note: This feature is available in Web Workers.

The to() method of the CSSNumericValue interface converts a numeric value from one unit to another.

Syntax

js
to(unit)

Parameters

unit

The unit to which you want to convert.

Return value

A CSSUnitValue.

Exceptions

SyntaxError DOMException

Thrown if an invalid unit was passed to the method.

TypeError

Thrown if:

Examples

undefined

Basic usage

js
// Prints "0.608542cm"
console.log(CSS.px("23").to("cm").toString());

Specifications