MDN self-hosted library · e01.org

CSSUnitValue: unit property

CSS Typed Object Model API

Open notebook · 1 cells web-api-instance-property upstream source

CSS Typed Object Model API

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.

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

Browser compatibility

See also