CSSUnitValue: unit property
Baseline 2026>
Newly available
Since November 2026, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Note: This feature is available in Web Workers.
The unit read-only property of the CSSUnitValue interface returns a string indicating the unit type.
Value
A string indicating the unit type, such as "em", "px", "percent", etc.
Examples
>Basic usage
The following code creates a CSSPositionValue from individual CSSUnitValue constructors, then queries the CSSUnitValue.unit.
js
const pos = new CSSPositionValue(
new CSSUnitValue(5, "px"),
new CSSUnitValue(10, "em"),
);
console.log(pos.x.unit); // "px"
console.log(pos.y.unit); // "em"
Specifications
| Specification |
|---|
| CSS Typed OM Level 1> # dom-cssunitvalue-unit> |
Browser compatibility
See also
CSSUnitValue.value- CSS numeric data types
- CSS values and units, a listing of all possible unit types
- Using the CSS Typed OM
- CSS Typed Object Model API