rem() CSS Function
The rem() function returns the remainder of dividing one value by another, keeping the sign of the first value, such as rem(18px, 5px).
Description
The rem() CSS function returns the remainder left over when the first argument (the dividend) is divided by the second argument (the divisor), just like the % operator in JavaScript. For example, rem(18px, 5px) is 3px, because 5px fits into 18px three times with 3px left over. Do not confuse it with the rem length unit, which is unrelated.
Both arguments must be of the same type, such as two lengths or two numbers, and the result has that type. The result always takes the sign of the dividend, so rem(-18px, 5px) is -3px. This is the key difference from mod(), whose result takes the sign of the divisor. If the divisor is 0, the result is NaN.
/* Leftover space after fitting as many 120px columns as possible */
.gutter {
padding-inline: calc(rem(100%, 120px) / 2);
}
/* Keep a rotation within one full turn, preserving direction */
.dial {
rotate: rem(var(--angle), 360deg);
}
rem() is one of the stepped value functions, with round() and mod().
Interactive Demo
Syntax
rem() = rem( <calc-sum>, <calc-sum> )
Values
- dividendA calculation resolving to a <number>, <dimension> or <percentage>. The value to be divided.
- divisorA calculation of the same type as the dividend. The value to divide by. The result has the same sign as the dividend.
Example
Browser Support
The following information will show you the current browser support for the CSS rem() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





