--- url: "https://web.dev/blog/css-stepped-value-functions" titulek: "The CSS stepped value math functions are now in Baseline 2024 | Blog | web.dev" h1: "The CSS stepped value math functions are now in Baseline 2024 Stay organized with collections Save and categorize content based on your preferences." popis: "The CSS math functions rem(), mod(), and round() are now interoperable." jazyk: "en" kanonicka: "https://web.dev/blog/css-stepped-value-functions" drobecky: ["Blog", "The CSS stepped value math functions are now in Baseline 2024"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 00:54:51" znaku: 3209 slov: 450 kodovani: "iso-8859-2" sha256: "dd679dc45c5908a9ad1c8f64f8a53055e557032368a3dfda22361c592fd67970" --- The CSS stepped value math functions are now in Baseline 2024 Stay organized with collections Save and categorize content based on your preferences. Rachel Andrew Published: May 14, 2024 All major engines now support the CSS stepped value math functions— [round()](https://developer.mozilla.org/docs/Web/CSS/round), [mod()](https://developer.mozilla.org/docs/Web/CSS/mod), and [rem()](https://developer.mozilla.org/docs/Web/CSS/rem). The stepped value functions all transform a given value according to another *step value*. The `round()` function The `round()` function takes a value to be rounded, a rounding interval, and an optional rounding strategy. The value is rounded according to the rounding strategy, to the nearest integer multiple of the rounding interval. Either the value to be rounded, or the rounded interval, should be a CSS custom property. While it's valid to hardcode both values, there's little point rounding a number if you could calculate the value yourself. The following CSS rounds the value of `--my-font-size`, to the interval of `1rem`. `font-size: round(var(--my-font-size), 1rem);` The default rounding strategy is `nearest`. The previous example including the rounding strategy is as follows: `font-size: round(nearest,var(--my-font-size), 1rem);` The possible values for the rounding strategy are: `up`: Equivalent to JavaScript `Math.ceil()` method. Rounds the value up to the nearest whole multiple of the rounding interval. `down`: Equivalent to JavaScript `Math.floor()` method. Rounds the value down to the nearest whole multiple of the rounding interval. `nearest` (default): Equivalent to JavaScript `Math.round()`. Rounds the value up or down, to the nearest whole multiple of the rounding interval. `to-zero`: Equivalent to JavaScript `Math.trunc()` method. Rounds the value to the nearest integer multiple of the rounding interval closer to zero. Learn more about `round()` in [The New CSS Math: `round()`](https://danielcwilson.com/posts/mathematicss-round/), by Dan Wilson. The `rem()` and `mod()` functions The `rem()` and `mod()` CSS functions work in a similar way to the JavaScript [remainder operator (%)](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Remainder). They take two values, the first (the dividend) is divided by the second (the divisor), and the remainder is returned. `margin: rem(18px, 5px); /* returns 3px */` The difference between the two functions is that `rem()` always takes the sign of the dividend, therefore if the first value is positive the returned value will be positive. The `mod()` function takes the sign of the divisor. Learn more about `rem()` and `mod()` in [The New CSS Math: `rem()` and `mod()`](https://danielcwilson.com/posts/mathematicss-rem-mod/), by Dan Wilson. Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see the [Google Developers Site Policies](https://developers.google.com/site-policies). Java is a registered trademark of Oracle and/or its affiliates. Last updated 2024-05-14 UTC.