MDN self-hosted library · e01.org

CSSMathClamp: value property

CSS Typed Object Model API

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

CSS Typed Object Model API

The value read-only property of the CSSMathClamp interface returns a CSSNumericValue instance representing its preferred value.

Value

A CSSNumericValue.

Examples

Basic usage

The following code creates a CSSMathClamp object, then reads its value.

const clamp = new CSSMathClamp(CSS.px(10), CSS.percent(50), CSS.px(500));

console.log(clamp.value); // CSSUnitValue {value: 50, unit: "percent"}
console.log(clamp.value.value); // 50
console.log(clamp.value.unit); // "percent"

value simply returns whatever CSSNumericValue was passed into the constructor — here that's a CSSUnitValue, since CSS.percent(50) is a CSSUnitValue. Passing a more complex expression, such as CSS.percent(50).add(CSS.em(2)) (a CSSMathSum), means value would return that CSSMathSum instead.

Specifications

Browser compatibility

See also

  • CSSMathClamp.lower
  • CSSMathClamp.upper