<timing-function>

  • Revision slug: CSS/timing-function
  • Revision title: timing-function
  • Revision id: 21956
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment 8 words removed

Revision Content

Summary

The <timing-function> CSS data type denotes a mathematical function that describes how fast one-dimensional values 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 ratio of the output value (expressed as a {{ xref_cssnumber() }}, 0.0 representing the initial state, 1.0 the final state.

TF_with_output_gt_than_1.pngTF_with_output_gt_than_1_clipped.pngThe output ratio can be greater than 1.0 (or smaller than 0.0). This will lead to go further than the final state, then to come back, a kind of bouncing effect.

Nevertheless, if the output value goes outside of its possible range, like a component of a color going greater than 255 or smaller than 0, the value is clipped to its nearest possible value (in the case of a color-component 255 and 0 respectively.

Some cubic-bezier() curves, e. g. when both ordinates are greater than 1.0, show this property.

Values

The cubic-bezier() class of timing-functions

cubic-bezier, example.png

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, P3 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 abscissa have 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.

When facing an invalid cubic-bezier curve, CSS will ignore the whole property.

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.

Examples

These cubic Bézier curves are valid for use in CSS :

cubic-bezier(0.1, 0.7, 1.0, 0.1)   The canonical Bézier curve with four <number> in the [0,1] range.
cubic-bezier(0, 0, 1, 1)           Using <integer> is valid as any <integer> is also a <number>.
cubic-bezier(-0.2, 0.6, -0.1, 0)   Negative values for abscissas are valid, leading to bouncing effects.
cubic-bezier(1.1, 0, 4, 0)         Values > 1.0 for abscissas are also valid.

These cubic Bézier curves definitions are invalid :

cubic-bezier(0.1, red, 1.0, green) Though the animated output type may be a color, Bézier curves work w/ numerical ratios.
cubic-bezier(0.1, 4,   0.6, 2.45)  Ordinates must be in the [0, 1] range or the curve is not a function of time.
cubic-bezier(0.3, 2.1)             The two points must be defined, there is no default value.
cubic-bezier(0.3, -1.9, 2.1, -0.2) Ordinates must be in the [0, 1] range or the curve is not a function of time.

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.

Examples

Keywords for common timing-functions

linear

cubic-bezier,linear.png

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

cubic-bezier,ease.png 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

cubic-bezier,ease-in.png

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

cubic-bezier,ease-in-out.png

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

cubic-bezer,ease-out.png

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


steps(1,start).pngThis 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

steps(1,end).png

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) {{ CompatVersionUnknown() }} {{ CompatNo() }} 10.5 3.1
cubic-bezier() w/ ordinate ∉ [0,1] 4.0 (2.0) {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} Nightly
steps() 4.0 (2.0) {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
Feature Firefox Mobile (Gecko) Android IE Phone Opera Mobile Safari Mobile
Basic support 4.0 (2.0) {{ CompatVersionUnknown() }} {{ CompatNo() }} 10 {{ CompatVersionUnknown() }}
cubic-bezier() w/ ordinate ∉ [0,1] 4.0 (2.0) {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
steps() 4.0 (2.0) {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}

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 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 ratio of the output value (expressed as a {{ xref_cssnumber() }}, <code>0.0</code> representing the initial state, <code>1.0</code> the final state.</p>
<p><a href="/@api/deki/files/5781/=TF_with_output_gt_than_1.png" title="TF_with_output_gt_than_1.png"><img align="left" alt="TF_with_output_gt_than_1.png" class="internal lwrap" src="/@api/deki/files/5781/=TF_with_output_gt_than_1.png?size=thumb" style="width: 120px; height: 160px;"></a><a href="/@api/deki/files/5782/=TF_with_output_gt_than_1_clipped.png" title="TF_with_output_gt_than_1_clipped.png"><img align="left" alt="TF_with_output_gt_than_1_clipped.png" class="internal lwrap" src="/@api/deki/files/5782/=TF_with_output_gt_than_1_clipped.png?size=thumb" style="width: 120px; height: 160px;"></a>The output ratio can be greater than 1.0 (or smaller than 0.0). This will lead to go further than the final state, then to come back, a kind of <em>bouncing</em> effect.</p>
<p>Nevertheless, if the output value goes outside of its possible range, like a component of a color going greater than <code>255</code> or smaller than <code>0</code>, the value is clipped to its nearest possible value (in the case of a color-component <code>255</code> and <code>0</code> respectively.</p>
<p>Some <code>cubic-bezier()</code> curves, e. g. when both ordinates are greater than <code>1.0</code>, show this property.</p><h2>Values</h2>
<div style="width:100%"> <h3>The <code>cubic-bezier()</code> class of timing-functions</h3>
<p><img align="left" alt="cubic-bezier, example.png" class="internal lwrap" src="/@api/deki/files/5780/=cubic-bezier%25252C_example.png" style=""></p>
<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>3</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 abscissa have 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>
<p>When facing an invalid <code>cubic-bezier</code> curve, CSS will ignore the whole property.</p></div>
<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>
<dl> <dt 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></dt> <dd style="margin-left: 40px;">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.</dd>
</dl>
<h4>Examples</h4>
<p>These cubic Bézier curves are valid for use in CSS :</p>
<pre><code>cubic-bezier(0.1, 0.7, 1.0, 0.1)   </code>The canonical Bézier curve with four &lt;number&gt; in the [0,1] range.
cubic-bezier(0, 0, 1, 1)           Using &lt;integer&gt; is valid as any &lt;integer&gt; is also a &lt;number&gt;.
cubic-bezier(-0.2, 0.6, -0.1, 0)   Negative values for abscissas are valid, leading to bouncing effects.
cubic-bezier(1.1, 0, 4, 0)         Values &gt; 1.0 for abscissas are also valid.
</pre>
<p>These cubic Bézier curves definitions are invalid :</p>
<pre>cubic-bezier(0.1, red, 1.0, green) Though the animated output type may be a color, Bézier curves work w/ numerical ratios.
cubic-bezier(0.1, 4,   0.6, 2.45)  Ordinates must be in the [0, 1] range or the curve is not a function of time.
cubic-bezier(0.3, 2.1)             The two points must be defined, there is no default value.
cubic-bezier(0.3, -1.9, 2.1, -0.2) Ordinates must be in the [0, 1] range or the curve is not a function of time.
</pre>
<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>{{ CompatVersionUnknown() }}</td> <td>{{ CompatNo() }}</td> <td>10.5 <a class="external" href="http://dev.opera.com/articles/view/css3-transitions-and-2d-transforms/" title="http://dev.opera.com/articles/view/css3-transitions-and-2d-transforms/"></a></td> <td>3.1</td> </tr> <tr> <td><code>cubic-bezier()</code> w/ ordinate ∉ [0,1]</td> <td>4.0 (2.0)</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>Nightly <a class="link-https" href="https://bugs.webkit.org/show_bug.cgi?id=45761" title="https://bugs.webkit.org/show_bug.cgi?id=45761"></a></td> </tr> <tr> <td><code>steps()</code></td> <td>4.0 (2.0)</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</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>4.0 (2.0)</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatNo() }}</td> <td>10 <a class="external" href="http://dev.opera.com/articles/view/css3-transitions-and-2d-transforms/" title="http://dev.opera.com/articles/view/css3-transitions-and-2d-transforms/"></a></td> <td>{{ CompatVersionUnknown() }}</td> </tr> <tr> <td><code>cubic-bezier()</code> w/ ordinate ∉ [0,1]</td> <td>4.0 (2.0)</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> <tr> <td><code>steps()</code></td> <td>4.0 (2.0)</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</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>
Revert to this revision