log() CSS Function
The log() function returns the logarithm of a number, the natural logarithm by default or in a given base, such as log(100, 10).
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
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
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.
Desktop





Tablets & Mobile





