Favorites

rem() CSS Function

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

The rem() function returns the remainder of dividing one value by another, keeping the sign of the first value, such as rem(18px, 5px).

☕
Enjoying this site?

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

Buy us a coffee

Description

The rem() CSS function returns the remainder left over when the first argument (the dividend) is divided by the second argument (the divisor), just like the % operator in JavaScript. For example, rem(18px, 5px) is 3px, because 5px fits into 18px three times with 3px left over. Do not confuse it with the rem length unit, which is unrelated.

Both arguments must be of the same type, such as two lengths or two numbers, and the result has that type. The result always takes the sign of the dividend, so rem(-18px, 5px) is -3px. This is the key difference from mod(), whose result takes the sign of the divisor. If the divisor is 0, the result is NaN.

/* Leftover space after fitting as many 120px columns as possible */
.gutter {
  padding-inline: calc(rem(100%, 120px) / 2);
}

/* Keep a rotation within one full turn, preserving direction */
.dial {
  rotate: rem(var(--angle), 360deg);
}

rem() is one of the stepped value functions, with round() and mod().

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: rem(270px, 100px);
}

Syntax

rem() = rem( <calc-sum>, <calc-sum> )

Values

  • dividendA calculation resolving to a <number>, <dimension> or <percentage>. The value to be divided.
  • divisorA calculation of the same type as the dividend. The value to divide by. The result has the same sign as the dividend.

Example

<div class="wrap">
<h1>CSS rem() examples</h1>
<div class="card list">
<div class="bar a"></div><div class="label">rem(260px, 100px) = 60px</div>
<div class="bar b"></div><div class="label">rem(390px, 100px) = 90px</div>
<div class="bar c"></div><div class="label">rem(450px, 200px) = 50px</div>
</div>
<p class="note">rem(-140px, 100px) would be -40px (sign of the dividend), while mod(-140px, 100px) is 60px.</p>
</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;
}

/* rem() 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; }
.a { width: rem(260px, 100px); }
.b { width: rem(390px, 100px); }
.c { width: rem(450px, 200px); }
Open in editor

Browser Support

The following information will show you the current browser support for the CSS rem() 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