Favorites

log() CSS Function

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

The log() function returns the logarithm of a number, the natural logarithm by default or in a given base, such as log(100, 10).

☕
Enjoying this site?

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

Buy us a coffee

Description

The log() CSS function returns the logarithm of a number. With one argument it calculates the natural logarithm (base e); with a second argument it uses that number as the base. For example, log(8, 2) is 3, because 2 must be multiplied by itself three times to make 8. Both arguments are plain <number> values and the result is a number.

Logarithms grow quickly at first and then slow down, which is the opposite of exp() and pow(). This makes log() useful for scales where large input values should only have a modest visual effect, such as sizing a badge according to a count, or converting a ratio back into a step number. A value of 0 returns -infinity, and negative values return NaN.

/* Bars that grow logarithmically with a data value */
.bar {
  width: calc(log(var(--value), 10) * 80px);
}

/* log(1000, 10) = 3, log(100, 10) = 2, log(10, 10) = 1 */
.bar[data-v="1000"] { --value: 1000; }

/* Natural logarithm */
.item {
  opacity: calc(log(var(--n)) / 3);
}

log() is part of the exponential function family with pow(), sqrt(), hypot() and exp().

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: calc(log(100, 10) * 100px);
}

Syntax

log() = log( <calc-sum>, <calc-sum>? )

Values

  • valueA calculation resolving to a <number> greater than 0.
  • baseOptional. A calculation resolving to a <number>: the base of the logarithm. If omitted, the natural logarithm (base e) is used.

Example

<div class="wrap">
<h1>CSS log() examples</h1>
<div class="card list">
<div class="bar" style="--v: 2"></div><div class="label">log(2, 2) * 40px = 40px</div>
<div class="bar" style="--v: 8"></div><div class="label">log(8, 2) * 40px = 120px</div>
<div class="bar" style="--v: 64"></div><div class="label">log(64, 2) * 40px = 240px</div>
<div class="bar" style="--v: 1024"></div><div class="label">log(1024, 2) * 40px = 400px</div>
</div>
<p class="note">The value grows 512 times, but the bar only grows 10 times.</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;
}

/* log() 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; }
.bar { width: calc(log(var(--v), 2) * 40px); }
Open in editor

Browser Support

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