round() CSS Function
The round() function rounds a value to the nearest multiple of an interval, with a rounding strategy: nearest, up, down or to-zero.
Description
The round() CSS function rounds a value to the nearest multiple of a rounding interval, using a chosen rounding strategy. For example, round(137px, 50px) rounds 137px to the nearest multiple of 50px, giving 150px. This is useful for snapping sizes to a grid, keeping elements aligned to a baseline, or avoiding fractional pixel values.
The optional first argument is the rounding strategy. nearest (the default) rounds to the closest multiple, with exact halves rounded up. up rounds toward positive infinity, down rounds toward negative infinity, and to-zero rounds toward zero. The value and the interval must be the same type. If the interval is left out it defaults to 1, which only works when the value is a plain number; for lengths you must give an interval, such as 1px.
/* Snap a fluid width to multiples of 40px */
.card {
width: round(down, 45vw, 40px);
}
/* Line height aligned to a 4px baseline grid */
p {
line-height: round(up, 1.4em, 4px);
}
/* Avoid sub-pixel positions */
.tooltip {
left: round(50% - 60px, 1px);
}
round() is one of the stepped value functions, together with mod() and rem().
Interactive Demo
Syntax
round() = round( <rounding-strategy>?, <calc-sum>, <calc-sum>? )
<rounding-strategy> = nearest | up | down | to-zero
Values
- <rounding-strategy>Optional. nearest (default) rounds to the closest multiple; up rounds toward +∞; down rounds toward -∞; to-zero rounds toward zero.
- valueToRoundA calculation resolving to a <number>, <dimension> or <percentage>.
- roundingIntervalOptional. A calculation of the same type giving the step to round to. Defaults to 1, which is only valid when the value is a <number>.
Example
Browser Support
The following information will show you the current browser support for the CSS round() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





