abs() CSS Function
The abs() function returns the absolute value of its argument, the same value without its sign, so -20px becomes 20px.
Description
The abs() CSS function returns the absolute value of its argument: the same value without its sign. Positive values are unchanged and negative values become positive, so abs(-20px) is 20px and abs(20px) is also 20px. The argument can be any numeric type, such as a number, length, angle or percentage, and the result keeps that type.
abs() is handy when a value is calculated from custom properties that might be negative, but the property it is used in only accepts positive values or should always move in one direction. For example, a shadow size, a border width or a distance between two points must never be negative. Note that when a percentage is involved, abs() works on the resolved value, so abs(20% - 100px) depends on what the percentage resolves to.
/* Distance between two offsets is always positive */
.gap {
width: abs(var(--end) - var(--start));
}
/* Shadow size based on a tilt that may be negative */
.card {
box-shadow: 0 0 abs(var(--tilt) * 2px) rgb(0 0 0 / 0.3);
}
abs() is a sign-related function together with sign(). Combining them reconstructs the original value: calc(sign(x) * abs(x)) equals x.
Interactive Demo
Syntax
abs() = abs( <calc-sum> )
Values
- <calc-sum>A calculation resolving to a <number>, <dimension> or <percentage>. The function returns the same value with a positive sign.
Example
Browser Support
The following information will show you the current browser support for the CSS abs() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





