Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1024506 of <timing-function>

  • Revision slug: Web/CSS/timing-function
  • Revision title: <timing-function>
  • Revision id: 1024506
  • Created:
  • Creator: Konrud
  • Is current revision? No
  • Comment

Revision Content

{{CSSRef}}

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. These functions are often called easing functions.

It is a function linking the time with a ratio of the output value, expressed as a {{xref_cssnumber}}, with 0.0 representing the initial state, 1.0 the final state.

The output ratio can be greater than 1.0 (or smaller than 0.0). This causes the animation to go farther than the final state, then come back, in a kind of bouncing effect.

Nevertheless, if the output value goes outside of its possible range, such as a component of a color going greater than 255 or smaller than 0, the value is clipped to its closest allowed value (in the case of a color-component 255 and 0 respectively. Some cubic-bezier() curves exhibit this property.

Values

CSS supports two kinds of timing functions: the subset of the cubic Bézier curves that are functions and staircase functions. The most useful of these functions are given a keyword that allows to easily describe them.

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, 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.

Cubic Bézier curves with the P1 or P2 ordinate outside the [0, 1] range may generate bouncing effects.

When you specify an invalid cubic-bezier curve, CSS ignores the whole property.

Syntax

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

where :

x1, y1, x2, y2
Are {{xref_cssnumber}} values 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 :

/* The canonical Bézier curve with four <number> in the [0,1] range. */
cubic-bezier(0.1, 0.7, 1.0, 0.1)   

/* Using <integer> is valid as any <integer> is also a <number>. */
cubic-bezier(0, 0, 1, 1)           

/* Negative values for ordinates are valid, leading to bouncing effects.*/
cubic-bezier(0.1, -0.6, 0.2, 0)    

/* Values > 1.0 for ordinates are also valid. */
cubic-bezier(0, 1.1, 0.8, 4)       

These cubic Bézier curves definitions are invalid :

/* Though the animated output type may be a color, 
   Bézier curves work w/ numerical ratios.*/
cubic-bezier(0.1, red, 1.0, green) 

/* Abscissas must be in the [0, 1] range or 
   the curve is not a function of time. */
cubic-bezier(2.45, 0.6, 4, 0.1)    

/* The two points must be defined, there is no default value. */
cubic-bezier(0.3, 2.1)   

/* Abscissas must be in the [0, 1] range or 
   the curve is not a function of time. */
cubic-bezier(-1.9, 0.3, -0.2, 2.1) 

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.

steps(2, start) steps(4, end)

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.
end is the default.

Examples

These timing functions are valid :

/* There is 5 treads, the last one happens 
   right before the end of the animation. */
steps(5, end)

/* A two-step staircase, the first one happening 
   at the start of the animation. */
steps(2, start)        

/* The second parameter is optional. */
steps(2)               

These timing function are invalid :

/* The first parameter must be an <integer> and 
   cannot be a real value, even if it is equal to one. */
steps(2.0, end)

/* The amount of steps must be non-negative. */
steps(-3, start)

/* There must be at least one step.*/
steps(0, end)       

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 already starts to slow down near the middle 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 then slows down when approaching its final state. At the beginning, 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
{{SpecName('CSS3 Transitions', '#transition-timing-function', '<timing-function>')}} {{Spec2('CSS3 Transitions')}} Defined anonymously
{{SpecName('CSS3 Animations', '#animation-timing-function', '<timing-function>')}} {{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) 4.0 10 10.5 3.1
cubic-bezier() w/ ordinate ∉ [0,1] 4.0 (2.0) 16.0 10 12.1 Nightly
steps() 4.0 (2.0) 8.0 10 12.1 5.1
Feature Firefox Mobile (Gecko) Android IE Phone Opera Mobile Safari Mobile
Basic support 4.0 (2.0) 4.0 {{CompatNo}} 10 2.0
cubic-bezier() w/ ordinate ∉ [0,1] 4.0 (2.0) {{CompatVersionUnknown}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
steps() 4.0 (2.0) 4.0 {{CompatNo}} {{CompatNo}} 5.0

See also

  • The {{cssxref("transition-timing-function")}} and {{cssxref("animation-timing-function")}} needing a <timing-function> value.
  • CSS Reference

Revision Source

<div>{{CSSRef}}</div>

<h2 id="Summary">Summary</h2>

<p>The <code>&lt;timing-function&gt;</code> <a href="/en-US/docs/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. These functions are often called <em>easing functions<code>.</code></em></p>

<p>It is a function linking the time with a ratio of the output value, expressed as a {{xref_cssnumber}}, with <code>0.0</code> representing the initial state, <code>1.0</code> the final state.</p>

<p><img src="/files/3434/TF_with_output_gt_than_1.png" /><img src="/files/3435/TF_with_output_gt_than_1_clipped.png" style="margin-right:5px" /></p>

<p>The output ratio can be greater than 1.0 (or smaller than 0.0). This causes the animation to go farther than the final state, then come back, in a kind of <em>bouncing</em> effect.</p>

<p>Nevertheless, if the output value goes outside of its possible range, such as a component of a color going greater than <code>255</code> or smaller than <code>0</code>, the value is clipped to its closest allowed value (in the case of a color-component <code>255</code> and <code>0</code> respectively. Some <code>cubic-bezier()</code> curves exhibit this property.</p>

<h2 class="cleared" id="Values">Values</h2>

<div style="width:100%">
<p>CSS supports two kinds of timing functions: the subset of the cubic Bézier curves that are functions and staircase functions. The most useful of these functions are given a <em>keyword</em> that allows to easily describe them.</p>

<h3 id="The_cubic-bezier()_class_of_timing-functions">The <code>cubic-bezier()</code> class of timing-functions</h3>

<table class="withoutBorder">
 <tbody>
  <tr>
   <td><img src="/files/3433/cubic-bezier,%20example.png" style="float:left" /></td>
   <td>
    <p>The <code>cubic-bezier()</code> functional notation defines a <a href="https://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 href="https://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>Cubic Bézier curves with the P<sub>1</sub> or P<sub>2</sub> ordinate outside the <code>[0, 1]</code> range may generate <em>bouncing</em> effects.</p>

    <p>When you specify an invalid <code>cubic-bezier</code> curve, CSS ignores the whole property.</p>
   </td>
  </tr>
 </tbody>
</table>
</div>

<h4 id="Syntax">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><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>Are {{xref_cssnumber}} values 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 id="Examples">Examples</h4>

<p>These cubic Bézier curves are valid for use in CSS :</p>

<pre>
/* The canonical Bézier curve with four &lt;number&gt; in the [0,1] range. */
cubic-bezier(0.1, 0.7, 1.0, 0.1)   

/* Using &lt;integer&gt; is valid as any &lt;integer&gt; is also a &lt;number&gt;. */
cubic-bezier(0, 0, 1, 1)           

/* Negative values for ordinates are valid, leading to bouncing effects.*/
cubic-bezier(0.1, -0.6, 0.2, 0)    

/* Values &gt; 1.0 for ordinates are also valid. */
cubic-bezier(0, 1.1, 0.8, 4)       </pre>

<p>These cubic Bézier curves definitions are invalid :</p>

<pre>
/* Though the animated output type may be a color, 
   Bézier curves work w/ numerical ratios.*/
cubic-bezier(0.1, red, 1.0, green) 

/* Abscissas must be in the [0, 1] range or 
   the curve is not a function of time. */
cubic-bezier(2.45, 0.6, 4, 0.1)    

/* The two points must be defined, there is no default value. */
cubic-bezier(0.3, 2.1)   

/* Abscissas must be in the [0, 1] range or 
   the curve is not a function of time. */
cubic-bezier(-1.9, 0.3, -0.2, 2.1) 
</pre>

<h3 id="The_steps()_class_of_timing-functions">The <code>steps()</code> class of timing-functions</h3>

<table class="withoutBorder">
 <tbody>
  <tr>
   <td><img src="/files/3436/steps(2,start).png" style="height:332px; width:248px" /></td>
   <td><img src="/files/3437/steps(4,end).png" style="height:332px; width:248px" /></td>
   <td rowspan="2">
    <p>The <code>steps()</code> functional notation defines a <a href="https://en.wikipedia.org/wiki/Step_function">step function</a> dividing the domain of output values in equidistant steps.</p>

    <p>This subclass of step functions are sometimes also called staircase functions.</p>
   </td>
  </tr>
  <tr style="text-align: center;">
   <td style="white-space: nowrap;"><code>steps(2, start)</code></td>
   <td><code>steps(4, end)</code></td>
  </tr>
 </tbody>
</table>

<h4 id="Syntax_2">Syntax</h4>

<pre>
<code>steps(<em>number_of_steps</em>, <em>direction</em>)</code>
</pre>

<p>where :</p>

<dl>
 <dt><strong><em>number_of_steps</em></strong></dt>
 <dd>Is a strictly positive {{xref_cssinteger}} representing the amount of equidistant treads composing the stepping function.</dd>
 <dt><strong><em>direction</em></strong></dt>
 <dd>Is a keyword indicating if it the function is <a href="https://en.wikipedia.org/wiki/Left-continuous#Directional_and_semi-continuity">left- or right-continuous</a>:
 <ul>
  <li><code>start</code> denotes a left-continuous function, so that the first step happens when the animation begins;</li>
  <li><code>end</code> denotes a right-continuous function, so that the last step happens when the animation ends.</li>
 </ul>
 <code>end</code> is the default.</dd>
</dl>

<h4 id="Examples_2">Examples</h4>

<p>These timing functions are valid :</p>

<pre>
/* There is 5 treads, the last one happens 
   right before the end of the animation. */
steps(5, end)

/* A two-step staircase, the first one happening 
   at the start of the animation. */
steps(2, start)        

/* The second parameter is optional. */
steps(2)               
</pre>

<p>These timing function are invalid :</p>

<pre>
/* The first parameter must be an <a href="/en-US/docs/Web/CSS/integer">&lt;integer&gt;</a> and 
   cannot be a real value, even if it is equal to one. */
steps(2.0, end)

/* The amount of steps must be non-negative. */
steps(-3, start)

/* There must be at least one step.*/
steps(0, end)       
</pre>

<h3 id="Keywords_for_common_timing-functions">Keywords for common timing-functions</h3>

<h4 id="linear"><code>linear</code></h4>

<table class="withoutBorder">
 <tbody>
  <tr style="vertical-align: top;">
   <td><img src="/files/3425/cubic-bezier,linear.png" style="height:332px; width:249px" /></td>
   <td>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.</td>
  </tr>
 </tbody>
</table>

<h4 id="ease"><code>ease</code></h4>

<table class="withoutBorder">
 <tbody>
  <tr style="vertical-align: top;">
   <td><img src="/files/3429/cubic-bezier,ease.png" style="height:332px; width:244px" /></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-US/docs/CSS/timing-function#ease-in-out"><code>ease-in-out</code></a>, though it accelerates more sharply at the beginning and the acceleration already starts to slow down near the middle of it.</td>
  </tr>
 </tbody>
</table>

<h4 id="ease-in"><code>ease-in</code></h4>

<table class="withoutBorder">
 <tbody>
  <tr style="vertical-align: top;">
   <td><img src="/files/3426/cubic-bezier,ease-in.png" style="height:332px; width:249px" /></td>
   <td>This keyword represents the timing function <code>cubic-bezier(0.42, 0.0, 1.0, 1.0)</code>. The animation begins slowly, then progressively accelerates until the final state is reached and the animation stops abruptly.</td>
  </tr>
 </tbody>
</table>

<h4 id="ease-in-out"><code>ease-in-out</code></h4>

<table class="withoutBorder">
 <tbody>
  <tr style="vertical-align: top;">
   <td><img src="/files/3428/cubic-bezier,ease-in-out.png" style="height:332px; width:244px" /></td>
   <td>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 then slows down when approaching its final state. At the beginning, it behaves similarly to the <a href="/en-US/docs/CSS/timing-function#ease-in"><code>ease-in</code></a> function; at the end, it is similar to the <a href="/en-US/docs/CSS/timing-function#ease-out"><code>ease-out</code></a> function.</td>
  </tr>
 </tbody>
</table>

<h4 id="ease-out"><code>ease-out</code></h4>

<table class="withoutBorder">
 <tbody>
  <tr style="vertical-align: top;">
   <td><img src="/files/3427/cubic-bezer,ease-out.png" style="height:332px; width:249px" /></td>
   <td>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.</td>
  </tr>
 </tbody>
</table>

<h4 id="step-start"><code>step-start</code></h4>

<table class="withoutBorder">
 <tbody>
  <tr>
   <td><img src="/files/3423/steps(1,start).png" style="height:332px; width:248px" />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>&nbsp;</td>
  </tr>
 </tbody>
</table>

<h4 id="step-end"><code>step-end</code></h4>

<table class="withoutBorder">
 <tbody>
  <tr style="vertical-align: top;">
   <td><img src="/files/3424/steps(1,end).png" style="height:332px; width:248px" /></td>
   <td>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.</td>
  </tr>
 </tbody>
</table>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th>Specification</th>
   <th>Status</th>
   <th>Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('CSS3 Transitions', '#transition-timing-function', '&lt;timing-function&gt;')}}</td>
   <td>{{Spec2('CSS3 Transitions')}}</td>
   <td>Defined anonymously</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS3 Animations', '#animation-timing-function', '&lt;timing-function&gt;')}}</td>
   <td>{{Spec2('CSS3 Animations')}}</td>
   <td>Defined anonymously, says to see definition in the CSS Transitions Module</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>{{CompatibilityTable}}</div>

<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>4.0</td>
   <td>10</td>
   <td>10.5</td>
   <td>3.1</td>
  </tr>
  <tr>
   <td><code>cubic-bezier()</code> w/ ordinate ∉ [0,1]</td>
   <td>4.0 (2.0)</td>
   <td>16.0</td>
   <td>10</td>
   <td>12.1</td>
   <td>Nightly</td>
  </tr>
  <tr>
   <td><code>steps()</code></td>
   <td>4.0 (2.0)</td>
   <td>8.0</td>
   <td>10</td>
   <td>12.1</td>
   <td>5.1</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>4.0</td>
   <td>{{CompatNo}}</td>
   <td>10</td>
   <td>2.0</td>
  </tr>
  <tr>
   <td><code>cubic-bezier()</code> w/ ordinate ∉ [0,1]</td>
   <td>4.0 (2.0)</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>steps()</code></td>
   <td>4.0 (2.0)</td>
   <td>4.0</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>5.0</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">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-US/docs/Web/CSS/Reference">CSS Reference</a></li>
</ul>
Revert to this revision