CSSUnitValue: unit property

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

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

The **unit** read-only property of the {{domxref("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 {{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