Get to know MDN better
Since May 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The mod() CSS function returns a modulus left over when the first parameter is divided by the second parameter, similar to the JavaScript remainder operator (%). The modulus is the value left over when one operand, the dividend, is divided by a second operand, the divisor. It always takes the sign of the divisor.
The calculation is a - (Math.floor(a / b) * b). For example, the CSS mod(21, -4) function returns the remainder of -3. The full calculation is 21 - (Math.floor(21 / -4) * -4). When dividing 21 by -4, the result is -5.25. This is floored to -6. Multiplying -6 by -4 is 24. Subtracting this 24 from the original 21, the remainder is -3.
The mod(dividend, divisor) function accepts two comma-separated values as its parameters. Both parameters must have the same type, number, dimension, or <percentage>, for the function to be valid. While the units in the two parameters don't need to be the same, they do need of the same dimension type, such as <length>, <angle>, <time>, or <frequency> to be valid.
dividendA calculation that resolves to a <number>, <dimension>, or <percentage> representing the dividend.
divisorA calculation that resolves to a <number>, <dimension>, or <percentage> representing the divisor.
Returns a <number>, <dimension>, or <percentage> (corresponds to the parameters' type) representing the modulus, that is, the operation left over.
| CSS Values and Units Module Level 4 # funcdef-mod |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Apr 18, 2026 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.