mozilla

# Revision 21934 of <timing-function>

• Revision slug: CSS/timing-function
• Revision title: timing-function
• Revision id: 21934
• Created:
• Creator: teoli
• Is current revision? No
• Comment 20 words added, 20 words removed
Tags:

## Summary

The `<timing-function>` CSS data type denotes a mathematical function that describes how fast one-dimensional values must change during transitions or animations. This in essence lets you establish an acceleration curve, so that the speed of the animation can vary over its duration.

It is a function linking the time with a percentage value (expressed as a {{ xref_cssnumber() }}, `0.0` representing the initial state, `1.0` the final state.

Negative and greater-than-one values are allowed leading the animation or transition going further than the final, or initial, state, than going back. Also, if the function gives values outside the possible range, like a composant-color value greater than `255` in the `rgb()` coordinates, the value is clipped to its nearest possible value.

## Values

### The `cubic-bezier()` class of timing-functions

The `cubic-bezier()` functional notation defines a cubic Bézier curve. As these curves are continuous, they are often used to smooth down the start and end of the animation and are therefore sometimes called easing functions.

A cubic Bézier curve is defined by four points P0, P1, P2 and P3. P0 and P3 are the start and the end of the curve and, in CSS these points are fixed as the coordinates are ratios (the abscissa the ratio of time, the ordinate the ratio of the output range). P0 is `(0, 0)` and represents the initial time and the initial state, P1 is `(1, 1)` and represents the final time and the final state.

Not all cubic Bézier curves are suitable as timing functions as not all are mathematical functions, i. e. curves that for a given x has zero or one value. With P0 and P3 fixed as defined by CSS, a cubic Bézier curve is a function, and is therefore valid, if and only if the abscissas of P1 and P2 are both in the `[0, 1]` range.

#### Syntax

````cubic-bezier(x1, y1, x2, y2)`
```

where :

x1, y1, x2, y2

Are {{ xref_cssnumber() }} representing the abscissas and ordinates of the P1 and P2 points defining the cubic Bézier curve. x1 and x2 must be in the range [0, 1] or the value is invalid.

### The `steps()` class of timing-functions

The `steps()` functional notation defines a step function dividing the domain of output values in equidistant steps. This subclass of step functions are sometimes also called staircase functions.

#### Syntax

````steps(number_of_steps, direction)`
```

where :

number_of_steps
Is a strictly positive {{ xref_cssinteger() }} representing the amount of equidistant treads composing the stepping function.
direction
Is a keyword indicating if it the function is left- or right-continuous:
• `start` denotes a left-continuous function, so that the first step happens when the animation begins;
• `end` denotes a right-continuous function, so that the last step happens when the animation ends.

### Keywords for common timing-functions

#### `linear`

 This keyword represents the timing function `cubic-bezier(``0.0, 0.0, 1.0, 1.0``)`. Using this timing function, the animation goes from its initial state to its final one regularly, with a constant speed.

#### `ease`

 This keyword represents the timing function `cubic-bezier(0.25, 0.1, 0.25, 1.0)`. This function is similar to `ease-in-out`, though it accelerates more sharply at the beginning and the acceleration and already starts to slow down near the medium of it.

#### `ease-in`

 This keyword represents the timing function `cubic-bezier(``0.42, 0.0, 1.0, 1.0``)`. The animation begins slowly, then progressively accelerates until the final state is reached and the animation stops abruptly.

#### `ease-in-out`

 This keyword represents the timing function `cubic-bezier(``0.42, 0.0, 0.58, 1.0``)`. With this timing function, the animation starts slowly, accelerates than slows down when approaching to its final state. At the begin, it behaves similarly to the `ease-in` function, at the end, it is similar to the `ease-out` function.

#### `ease-out`

 This keyword represents the timing function `cubic-bezier(``0.0, 0.0, 0.58, 1.0``)`. The animation starts quickly then slow progressively down when approaching to its final state.

#### `step-start`

 This keyword represents the timing function `steps(1, start)`. Using this timing function, the animation jumps immediately to the end state and stay in that position until the end of the animation.

#### `step-end`

 This keyword represents the timing function `steps(1, end)`. Using this timing function, the animation stays in its initial state until the end, where it directly jumps to its final position.

## Specifications

Specification Status Comment
CSS Transitions Level 3 {{ Spec2('CSS3 Transitions') }} Defined anonymously
CSS Animations Level 3 {{ Spec2('CSS3 Animations') }} Defined anonymously, says to see definition in the CSS Transitions Module

## Browser compatibility

{{ CompatibilityTable() }}

Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support 4.0 (2.0) yes {{ CompatUnknown() }} {{ CompatUnknown() }} 3.1
`cubic-bezier(x, y, z, w ∉ [0,1])` 4.0 (2.0) {{ CompatNo() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatNo() }}
`steps()` 4.0 (2.0) {{ CompatNo() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatNo() }}
Feature Firefox Mobile (Gecko) Android IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}
`cubic-bezier(x, y, z, w ∉ [0,1])` {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}
`steps()` {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

## See also

• The {{ cssxref("transition-timing-function") }} and {{ cssxref("animation-timing-function") }} needing a `<timing-function>` value.
• CSS Reference index
• CSS Data Types : {{ CSSDataTypes() }}

## Revision Source

```<h2>Summary</h2>
<p>The <code>&lt;timing-function&gt;</code> <a href="/en/CSS" title="CSS">CSS</a> data type denotes a mathematical function that describes how fast one-dimensional values must change during transitions or animations. This in essence lets you establish an acceleration curve, so that the speed of the animation can vary over its duration.</p>
<p>It is a function linking the time with a percentage value (expressed as a {{ xref_cssnumber() }}, <code>0.0</code> representing the initial state, <code>1.0</code> the final state.</p>
<p>Negative and greater-than-one values are allowed leading the animation or transition going further than the final, or initial, state, than going back. Also, if the function gives values outside the possible range, like a composant-color value greater than <code>255</code> in the <code>rgb()</code> coordinates, the value is clipped to its nearest possible value.</p>
<h2>Values</h2>
<h3>The <code>cubic-bezier()</code> class of timing-functions</h3>
<p>The <code>cubic-bezier()</code> functional notation defines a <a class=" external" href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves" title="http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves">cubic Bézier curve</a>. As these curves are continuous, they are often used to smooth down the start and end of the animation and are therefore sometimes called <em>easing functions</em>.</p>
<p>A cubic Bézier curve is defined by four points P<sub>0</sub>, P<sub>1</sub>, P<sub>2</sub> and P<sub>3</sub>. P<sub>0</sub> and P<sub>3</sub> are the start and the end of the curve and, in CSS these points are fixed as the coordinates are ratios (the abscissa the ratio of time, the ordinate the ratio of the output range). P<sub>0</sub> is <code>(0, 0)</code> and represents the initial time and the initial state, P<sub>1</sub> is <code>(1, 1)</code> and represents the final time and the final state.</p>
<p>Not all cubic Bézier curves are suitable as timing functions as not all are <a class=" external" href="http://en.wikipedia.org/wiki/Function_%28mathematics%29" title="http://en.wikipedia.org/wiki/Function_%28mathematics%29">mathematical functions</a>, i. e. curves that for a given x has zero or one value. With P<sub>0</sub> and P<sub>3</sub> fixed as defined by CSS, a cubic Bézier curve is a function, and is therefore valid, if and only if the abscissas of P<sub>1</sub> and P<sub>2</sub> are both in the <code>[0, 1]</code> range.</p>
<h4>Syntax</h4>
<pre><code>cubic-bezier(<em>x<sub>1</sub></em>, <em>y<sub>1</sub></em>, <em>x<sub>2</sub></em>, <em>y<sub>2</sub></em>)</code>
</pre>
<p>where :</p>
<p style="margin-left: 40px;"><strong><em>x<sub>1</sub></em>, <em>y<sub>1</sub></em>, <em>x<sub>2</sub></em>, <em>y<sub>2</sub></em></strong></p>
<p style="margin-left: 80px;">Are {{ xref_cssnumber() }} representing the abscissas and ordinates of the P<sub>1</sub> and P<sub>2</sub> points defining the cubic Bézier curve. x<sub>1</sub> and x<sub>2</sub> must be in the range [0, 1] or the value is invalid.</p>
<h4>Examples</h4><h3>The <code>steps()</code> class of timing-functions</h3>
<p>The <code>steps()</code> functional notation defines a <a class="external" href="http://en.wikipedia.org/wiki/Step_function" title="http://en.wikipedia.org/wiki/Step_function">step function</a> dividing the domain of output values in equidistant steps. This subclass of step functions are sometimes also called staircase functions.</p>
<h4>Syntax</h4>
<pre><code>steps(<em>number_of_steps</em>, <em>direction</em>)</code>
</pre>
<p>where :</p>
<dl> <dt style="margin-left: 40px;"><strong><em>number_of_steps</em></strong></dt> <dd style="margin-left: 40px;">Is a strictly positive {{ xref_cssinteger() }} representing the amount of equidistant treads composing the stepping function.</dd> <dt style="margin-left: 40px;"><strong><em>direction</em></strong></dt> <dd style="margin-left: 40px;">Is a keyword indicating if it the function is <a class="external" href="http://en.wikipedia.org/wiki/Left-continuous#Directional_and_semi-continuity" title="http://en.wikipedia.org/wiki/Left-continuous#Directional_and_semi-continuity">left- or right-continuous</a>: <ul> <li style="margin-left: 40px;"><code>start</code> denotes a left-continuous function, so that the first step happens when the animation begins;</li> <li style="margin-left: 40px;"><code>end</code> denotes a right-continuous function, so that the last step happens when the animation ends.</li> </ul> </dd>
</dl>
<h4>Examples</h4><h3>Keywords for common timing-functions</h3>
<h4><code>linear</code></h4>
<table border="0" cellpadding="1" cellspacing="1" style="width: 100%;"> <tbody> <tr style="vertical-align: top;"> <td><a href="/@api/deki/files/5765/=cubic-bezier%25252Clinear.png" title="cubic-bezier,linear.png"><img alt="cubic-bezier,linear.png" class="internal default" src="/@api/deki/files/5765/=cubic-bezier%25252Clinear.png?size=thumb" style="width: 111px; height: 160px;"></a></td> <td> <p>This keyword represents the timing function <code>cubic-bezier(</code><code>0.0, 0.0, 1.0, 1.0</code><code>)</code>. Using this timing function, the animation goes from its initial state to its final one regularly, with a constant speed.</p> </td> </tr> </tbody>
</table>
<h4><code>ease</code></h4>
<table border="0" cellpadding="1" cellspacing="1" style="width: 100%;"> <tbody> <tr style="vertical-align: top;"> <td><a href="/@api/deki/files/5769/=cubic-bezier%25252Cease.png" title="cubic-bezier,ease.png"><img alt="cubic-bezier,ease.png" class="internal default" src="/@api/deki/files/5769/=cubic-bezier%25252Cease.png?size=thumb" style="width: 117px; height: 160px;"></a></td> <td>This keyword represents the timing function <code>cubic-bezier(0.25, 0.1, 0.25, 1.0)</code>. This function is similar to <a href="/en/CSS/timing-function#ease-in-out" title="https://developer.mozilla.org/en/CSS/timing-function#ease-in-out"><code>ease-in-out</code></a>, though it accelerates more sharply at the beginning and the acceleration and already starts to slow down near the medium of it.</td> </tr> </tbody>
</table>
<h4><code>ease-in</code></h4>
<table border="0" cellpadding="1" cellspacing="1" style="width: 100%;"> <tbody> <tr style="vertical-align: top;"> <td><a href="/@api/deki/files/5766/=cubic-bezier%25252Cease-in.png" title="cubic-bezier,ease-in.png"><img alt="cubic-bezier,ease-in.png" class="internal default" src="/@api/deki/files/5766/=cubic-bezier%25252Cease-in.png?size=thumb" style="width: 111px; height: 160px;"></a></td> <td> <p>This keyword represents the timing function <code>cubic-bezier(</code><code>0.42, 0.0, 1.0, 1.0</code><code>)</code>. The animation begins slowly, then progressively accelerates until the final state is reached and the animation stops abruptly.</p> </td> </tr> </tbody>
</table>
<h4><code>ease-in-out</code></h4>
<table border="0" cellpadding="1" cellspacing="1" style="width: 100%;"> <tbody> <tr style="vertical-align: top;"> <td><a href="/@api/deki/files/5768/=cubic-bezier%25252Cease-in-out.png" title="cubic-bezier,ease-in-out.png"><img alt="cubic-bezier,ease-in-out.png" class="internal default" src="/@api/deki/files/5768/=cubic-bezier%25252Cease-in-out.png?size=thumb" style="width: 121px; height: 160px;"></a></td> <td> <p>This keyword represents the timing function <code>cubic-bezier(</code><code>0.42, 0.0, 0.58, 1.0</code><code>)</code>. With this timing function, the animation starts slowly, accelerates than slows down when approaching to its final state. At the begin, it behaves similarly to the <a href="/en/CSS/timing-function#ease-in" title="https://developer.mozilla.org/en/CSS/timing-function#ease-in"><code>ease-in</code></a> function, at the end, it is similar to the <a href="/en/CSS/timing-function#ease-out" title="https://developer.mozilla.org/en/CSS/timing-function#ease-out"><code>ease-out</code></a> function.</p> </td> </tr> </tbody>
</table>
<h4><code>ease-out</code></h4>
<table border="0" cellpadding="1" cellspacing="1" style="width: 100%;"> <tbody> <tr style="vertical-align: top;"> <td><a href="/@api/deki/files/5767/=cubic-bezer%25252Cease-out.png" title="cubic-bezer,ease-out.png"><img alt="cubic-bezer,ease-out.png" class="internal default" src="/@api/deki/files/5767/=cubic-bezer%25252Cease-out.png?size=thumb" style="width: 111px; height: 160px;"></a></td> <td> <p>This keyword represents the timing function <code>cubic-bezier(</code><code>0.0, 0.0, 0.58, 1.0</code><code>)</code>. The animation starts quickly then slow progressively down when approaching to its final state.</p> </td> </tr> </tbody>
</table>
<h4><code>step-start</code></h4>
<br>
<table border="0" cellpadding="1" cellspacing="1" style="width: 100%;"> <tbody> <tr> <td><a href="/@api/deki/files/5763/=steps%2525281%25252Cstart%252529.png" title="steps(1,start).png"><img align="left" alt="steps(1,start).png" class="internal lwrap" src="/@api/deki/files/5763/=steps%2525281%25252Cstart%252529.png?size=webview" style="width: 119px; height: 159px;"></a>This keyword represents the timing function <code>steps(1, start)</code>. Using this timing function, the animation jumps immediately to the end state and stay in that position until the end of the animation.</td> <td> </td> </tr> </tbody>
</table>
<h4><code>step-end</code></h4>
<table border="0" cellpadding="1" cellspacing="1" style="width: 100%;"> <tbody> <tr style="vertical-align: top;"> <td><a href="/@api/deki/files/5764/=steps%2525281%25252Cend%252529.png" title="steps(1,end).png"><img alt="steps(1,end).png" class="internal default" src="/@api/deki/files/5764/=steps%2525281%25252Cend%252529.png?size=thumb" style="width: 111px; height: 160px;"></a></td> <td> <p>This keyword represents the timing function <code>steps(1, end)</code>. Using this timing function, the animation stays in its initial state until the end, where it directly jumps to its final position.</p> </td> </tr> </tbody>
</table>
<h2>Specifications</h2>
<table class="standard-table"> <thead> <tr style="background-color: rgb(255, 204, 255);"> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> </thead> <tbody> <tr> <td><a class="external" href="http://dev.w3.org/csswg/css3-transitions/#transition-timing-function" title="http://dev.w3.org/csswg/css3-transitions/#transition-timing-function">CSS Transitions Level 3</a></td> <td>{{ Spec2('CSS3 Transitions') }}</td> <td>Defined anonymously</td> </tr> <tr> <td><a class="external" href="http://dev.w3.org/csswg/css3-animations/#animation-timing-function_tag" title="http://dev.w3.org/csswg/css3-animations/#animation-timing-function_tag">CSS Animations Level 3</a></td> <td>{{ Spec2('CSS3 Animations') }}</td> <td>Defined anonymously, says to see definition in the CSS Transitions Module</td> </tr> </tbody>
</table>
<h2>Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Firefox (Gecko)</th> <th>Chrome</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari</th> </tr> <tr> <td>Basic support</td> <td>4.0 (2.0)</td> <td>yes</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>3.1</td> </tr> <tr> <td><code>cubic-bezier(x, y, z, w ∉ [0,1])</code></td> <td>4.0 (2.0)</td> <td>{{ CompatNo() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatNo() }}</td> </tr> <tr> <td><code>steps()</code></td> <td>4.0 (2.0)</td> <td>{{ CompatNo() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatNo() }}</td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Firefox Mobile (Gecko)</th> <th>Android</th> <th>IE Phone</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> <tr> <td><code>cubic-bezier(x, y, z, w ∉ [0,1])</code></td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> <tr> <td><code>steps()</code></td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> </tbody> </table>
</div>
<h2>See also</h2>
<ul> <li>The {{ cssxref("transition-timing-function") }} and {{ cssxref("animation-timing-function") }} needing a <code>&lt;timing-function&gt;</code> value.</li> <li><a href="/en/CSS_Reference" title="CSS Reference">CSS Reference</a> index</li> <li>CSS Data Types : {{ CSSDataTypes() }}</li>
</ul>```