exp()

Term side of the Card.
Topic: Mathematics
Unit title: exp()
Categories: Function
Explanation side of the Card

Explanation: The math function that returns the value of `e` (Euler's number) raised to the power of a given number. It's used in calculations involving exponential growth, decay or other mathematical models in programming.

Browser compatibility:
  • The chrome browser supports this feature starting from version 120.
  • The edge browser supports this feature starting from version 120.
  • The firefox browser supports this feature starting from version 118.
  • The safari browser supports this feature starting from version 15.4.
Availability: 

Example

Wrongcss
.box {
  width: exp(2rem);
}
Rightcss
.box {
  width: calc(exp(2) * 1rem);
}

exp() only takes numbers and returns a number, so it is multiplied by '1rem' to produce a width.

Common mistakes

  • Passing a length like exp(2px), which is invalid.

Key points

  • The argument is a plain number, not a length or percentage.
  • The number result is multiplied by a unit inside calc() when a length is needed.
  • pow() is used instead when the base is not e.

Interview questions

What is the difference between exp() and pow() in CSS?

exp(x) always raises e to the power x. pow() takes any base, like pow(2, 3).

Is there an e constant in CSS?

Yes. CSS math functions accept the e keyword, so calc(e * 1px) is valid.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy