Back to Content

CSSUnitValue: unit property

files/en-us/web/api/cssunitvalue/unit/index.md

latest908 B
Original Source

{{APIRef("CSS Typed Object Model API")}}

The CSSUnitValue.unit read-only property of the {{domxref("CSSUnitValue")}} interface returns a string indicating the type of unit.

Value

A string.

Examples

The following creates a {{domxref('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

{{Specifications}}

Browser compatibility

{{Compat}}

See also