web api instance property
CSSUnitValue: unit property
The CSSUnitValue.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", "%", etc.
Examples
The following creates a CSSPositionValue from individual
CSSUnitValue constructors, then queries the
CSSUnitValue.unit.
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
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.
See also
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