Rounding numbers in CSS used to mean JavaScript, Sass, or awkward calc() tricks. The CSS stepped-value functions round(), mod() and rem() fix that, and they’re about to cross an important line. According to the modern.css Baseline tracker, updated on 15 November 2026, “round(), mod(), and rem()” reach Baseline Widely available on 17 November 2026. That’s the label for features that have worked in all major browsers for 30 months, the point where most teams stop worrying about support. This tutorial explains each function, shows practical layout and design patterns, and covers the gotchas.
What “Widely available” means
Baseline is the W3C WebDX group’s label for features you can rely on. A feature becomes Newly available when it works in the latest Chrome, Edge, Firefox and Safari, and Widely available 30 months later. The stepped-value functions became Newly available in May 2024, when Chrome and Edge shipped them, joining Safari and Firefox, which already had them. As of 17 November they’re Widely available, so they’re safe for most production sites without a fallback.
You can check the details on MDN: round(), mod() and rem().
round(): snap a value to a step
The syntax is:
round(<rounding-strategy>?, <value>, <interval>?)
<value>is the number, length, angle or percentage you want to round.<interval>is the step to round to, such as8pxor1rem.<rounding-strategy>is optional and can benearest(the default),up,downorto-zero.
.example {
width: round(37px, 10px); /* 40px (nearest) */
width: round(up, 31px, 10px); /* 40px */
width: round(down, 39px, 10px); /* 30px */
width: round(to-zero, -39px, 10px);/* -30px */
}
Always pass an interval for values with units. If you leave it out, the interval defaults to 1, which only works for plain numbers. round(37.4px) is not a valid shortcut for “round to the nearest pixel”; write round(37.4px, 1px).
Pattern 1: snap fluid sizes to your spacing grid
Fluid sizes based on viewport units produce odd values like 23.7px. If your design system uses a 4px or 8px grid, round() keeps everything on it:
:root {
--space-unit: 4px;
}
.card {
/* Fluid padding, snapped to the 4px grid */
padding: round(clamp(12px, 2.5vw, 32px), var(--space-unit));
}
.hero-title {
/* Fluid type, snapped to whole pixels for crisper rendering */
font-size: round(clamp(1.75rem, 1rem + 3vw, 3.5rem), 1px);
}
Pattern 2: whole-column widths
Need a sidebar that’s always an exact multiple of a 120px column?
.sidebar {
inline-size: round(down, 30vw, 120px);
min-inline-size: 120px;
}
Using down guarantees the sidebar never exceeds 30% of the viewport while staying on the column grid.
Pattern 3: stop half-pixel blur
Elements centred with translate(-50%, -50%) can land on half pixels and look blurry, especially text in some browsers. Rounding the offset keeps them sharp:
.tooltip {
--offset: calc(var(--tooltip-width) / -2);
translate: round(var(--offset), 1px) 0;
}
mod() and rem(): remainders in CSS
Both functions return what’s left after dividing one value by another:
mod(<dividend>, <divisor>)
rem(<dividend>, <divisor>)
They give the same result for positive values. The difference shows up with negative numbers:
mod()takes the sign of the divisor.rem()takes the sign of the dividend.
.demo {
--a: mod(18px, 5px); /* 3px */
--b: rem(18px, 5px); /* 3px */
--c: mod(-18px, 5px); /* 2px (sign of the divisor) */
--d: rem(-18px, 5px); /* -3px (sign of the dividend) */
}
If you’ve used JavaScript, rem() behaves like the % operator, while mod() behaves like the “always positive” modulo many people expect when wrapping values.
Pattern 4: normalise angles
Custom properties that animate or accumulate rotation can grow past 360 degrees. mod() keeps them in range, even when values are negative:
.dial {
--angle: -450deg;
rotate: mod(var(--angle), 360deg); /* 270deg */
}
Pattern 5: hue cycling for generated palettes
Combine mod() with custom properties to build colour sets that wrap around the colour wheel:
.tag {
--base-hue: 210;
--step: 75;
}
.tag:nth-child(1) { --i: 0; }
.tag:nth-child(2) { --i: 1; }
.tag:nth-child(3) { --i: 2; }
.tag:nth-child(4) { --i: 3; }
.tag {
background: oklch(85% 0.08 mod(calc(var(--base-hue) + var(--i) * var(--step)), 360));
}
Each tag gets a hue 75 degrees further round the wheel, wrapped neatly into the 0–360 range.
Pattern 6: alternating rhythm without extra selectors
With an index variable, mod() can produce alternating values, such as a staggered offset for every second item:
.timeline-item {
/* 0 for even items, 1 for odd items */
--is-odd: mod(var(--i), 2);
margin-inline-start: calc(var(--is-odd) * 3rem);
}
Set --i on each item from your HTML or framework (for example style="--i: 3"). Newer sibling-index() support can remove that step in browsers that have it, but it isn’t Widely available yet, so keep the explicit variable for now.
Mixing units and types
The arguments must be of compatible types: you can round a length to a length (round(2.3rem, 1px)) because both resolve to lengths, but you can’t round a length to an angle. Inside calc()-style expressions everything resolves at computed or used-value time, so round(50%, 10px) works where percentages resolve to lengths, such as width.
Do you still need a fallback?
For most audiences, no. Users on browsers from before mid-2024 are rare. If you support older embedded browsers or kiosk devices, add a fixed value first and let modern browsers override it:
.card {
padding: 16px; /* fallback */
padding: round(clamp(12px, 2.5vw, 32px), 4px); /* modern */
}
Or wrap enhanced rules in a feature query:
@supports (width: round(1px, 1px)) {
.card { padding: round(clamp(12px, 2.5vw, 32px), 4px); }
}
What else is on the Baseline calendar
The same tracker lists :state() (custom element states) reaching Widely available on the same day, 17 November, with gradient interpolation, @starting-style, transition-behavior and registered custom properties following over the next few months. It’s a good time to retire older workarounds for all of them.
Takeaway
round(), mod() and rem() let CSS do its own maths: snap fluid values to your grid, avoid half-pixel blur, wrap angles and hues, and build rhythmic layouts, with no JavaScript. From 17 November 2026 they’re Baseline Widely available, so you can use them with confidence. Bookmark the MDN pages for round(), mod() and rem(), and start with the spacing-grid pattern.
