Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

abs() — absolute value

abs() returns a calculation’s non-negative magnitude while preserving its CSS numeric type.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

abs(<calc-sum>)

abs() uses abs(<calc-sum>) and returns a calculation’s non-negative magnitude while preserving its CSS numeric type. The result keeps the type required by the property grammar, so the function participates in value computation rather than text substitution.

The example sets a real CSS property: abs(-12px) computes to 12px, while the boundary case abs(0px) computes to 0px. The value comes from getComputedStyle and therefore exercises the computed-value stage.

Boundary behavior: it does not remove units or reconcile incompatible dimensions; the sign of negative zero is removed.

Examples

const a=document.createElement('div'),b=document.createElement('div');document.body.append(a,b);a.style.width='abs(-12px)';b.style.width='abs(0px)';console.log('negative='+getComputedStyle(a).width+'; used='+a.getBoundingClientRect().width+'; zero='+getComputedStyle(b).width);

Result

negative=12px; used=12; zero=0px

abs() returns a calculation’s non-negative magnitude while preserving its CSS numeric type.

Sources