Favorites

round() CSS Function

round()
CSS FunctionThis function is supported by all modern browsers.
Updated 21st November 2026

The round() function rounds a value to the nearest multiple of an interval, with a rounding strategy: nearest, up, down or to-zero.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

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

050px100px150px200px250px
Demo Code
HTML Code
<div class="demo-track">
	<div class="demo-element"></div>
</div>
<div class="demo-scale"><span>0</span><span>50px</span><span>100px</span><span>150px</span><span>200px</span><span>250px</span></div>
CSS Code
.demo-track {
	width: 300px;
	height: 36px;
	background: #f4f4f4 repeating-linear-gradient(90deg, #b0b0b0 0 1px, transparent 1px 50px);
	outline: 1px solid #c5c5c5;
}
.demo-scale {
	display: grid;
	grid-template-columns: repeat(6, 50px);
	width: 300px;
	font-size: 11px;
	color: #666;
}
.demo-element {
	height: 100%;
	background: linear-gradient(90deg, #f72585, #b5179e);
	width: round(170px, 50px);
}

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

<div class="wrap">
<h1>CSS round() examples</h1>
<div class="card list">
<div class="bar raw"></div><div class="label">137px (unrounded)</div>
<div class="bar nearest"></div><div class="label">round(nearest, 137px, 50px) = 150px</div>
<div class="bar up"></div><div class="label">round(up, 112px, 50px) = 150px</div>
<div class="bar down"></div><div class="label">round(down, 137px, 50px) = 100px</div>
<div class="bar zero"></div><div class="label">round(to-zero, 149px, 50px) = 100px</div>
</div>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* round() examples */
.bar {
height: 28px;
border-radius: 6px;
background: linear-gradient(90deg, #2563eb, #06b6d4);
max-width: 100%;
}

.track {
background: #e2e8f0;
border-radius: 6px;
overflow: hidden;
}

.list { display: grid; gap: 10px; }
.raw { width: 137px; background: #94a3b8; }
.nearest { width: round(nearest, 137px, 50px); }
.up { width: round(up, 112px, 50px); }
.down { width: round(down, 137px, 50px); }
.zero { width: round(to-zero, 149px, 50px); }
Open in editor

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.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee