CSS animation-timing-function Property

You are Here:

CSS animation-timing-function Property

CSS animation-timing-function property sets how an animation progresses through the duration of each cycle.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> div{ width: 100px; height: 100px; line-height: 5; text-align: center; border: 1px solid #000; background: #39ac39; -webkit-animation: myAnimation 1s infinite; /* Safari 4.0 - 8.0 */ animation: myAnimation 1s infinite; -webkit-animation-direction: alternate; /* Safari 4.0 - 8.0 */ animation-direction: alternate; } #point{ -webkit-animation-timing-function: linear; animation-timing-function: linear; } #point1{ -webkit-animation-timing-function: ease; animation-timing-function: ease; } #point2{ -webkit-animation-timing-function: ease-in; animation-timing-function: ease-in; } #point3{ -webkit-animation-timing-function: ease-out; animation-timing-function: ease-out; } #point4{ -webkit-animation-timing-function: ease-in-out; animation-timing-function: ease-in-out; } #point5{ -webkit-animation-timing-function: steps(infinite, jump-both); animation-timing-function: steps(infinite, jump-both); } #point6{ -webkit-animation-timing-function: cubic-bezier(0.83, 2.3, 0.31, 0.46); animation-timing-function: cubic-bezier(0.83, 2.3, 0.31, 0.46); } @-webkit-keyframes myAnimation { from {border-radius: 0%; background: #f69d3c;} to {border-radius: 50%; background: #0066ff} } @keyframes myAnimation { from {border-radius: 0%; background: #f69d3c;} to {border-radius: 50%; background: #0066ff} } </style> </head> <body> <h1>CSS animation-timing-function Property</h1> <h2>animation-timing-function: linear;</h2> <div id="point"> div </div> <h2>animation-timing-function: ease;</h2> <div id="point1"> div </div> <h2>animation-timing-function: ease-in;</h2> <div id="point2"> div </div> <h2>animation-timing-function: ease-out;</h2> <div id="point3"> div </div> <h2>animation-timing-function: ease-in-out;</h2> <div id="point4"> div </div> <h2>animation-timing-function: steps(infinite, jump-both);</h2> <div id="point5"> div </div> <h2>animation-timing-function: cubic-bezier(0.83, 2.3, 0.31, 0.46);</h2> <div id="point6"> div </div> </body> </html>

Syntax

Using CSS

element{ animation-timing-function: ease-in; }

Using Javascript

object.style.animationTimingFunction="ease-in";

Animatable

No, animation-timing-function property is not animatable. CSS Animatable Properties Reference.

Default Value

Default value for CSS animation-timing-function property is ease.

Property Value

The following table provides a list of values for CSS animation-timing-function property.

ValueExplanation
linearSpecifies that the animation has the same speed from start to end. It is equal to cubic-bezier(0.0, 0.0, 1.0, 1.0).
easeSpecifies that the animation has a slow start, then fast, before it ends slowly. It is equal to cubic-bezier(0.25, 0.1, 0.25, 1.0).
ease-inSpecifies that the animation starts off slowly, with the speed of the transition of the animating properting increasing until complete. It is equal to cubic-bezier(0.42, 0, 1.0, 1.0).
ease-outSpecifies that the animation starts quickly, slowing down the animation continues. It is equal to cubic-bezier(0, 0, 0.58, 1.0).
ease-in-outSpecifies that the animating properties slowly transitioning, speeding up, and then slowing down again. It is equal to cubic-bezier(0.42, 0, 0.58, 1.0).
steps(n, <option>) Specifies that the animation iteration along n stops along the transition, displaying each stop for equal lengths of time. Possible values for option are:
  • jump-start: Specifies a left-continuous function, so that the first jump happens when the animation begins.
  • jump-end: Specifies a right-continuous function, so that the last jump happens when the animation ends.
  • jump-none: Specifies that there is no jump on either end.
  • jump-both: Specifies that it includes pauses at both the 0% and 100% marks, effectively adding a step during the animation iteration.
  • start: Same as jump-start.
  • end: Same as jump-end.
cubic-bezier(n,n,n,n)Specifies your own values in the cubic-bezier function
Possible values are numeric values from 0 to 1.

Using JavaScript

In the following example, we will demonstrate how to change the CSS animation-timing-function property of an element using JavaScript.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> div{ width: 100px; height: 100px; line-height: 5; text-align: center; border: 1px solid #000; background: #39ac39; margin-bottom: 20px; } @-webkit-keyframes myAnimation { from {border-radius: 0%; background: #f69d3c;} to {border-radius: 50%; background: #0066ff} } @keyframes myAnimation { from {border-radius: 0%; background: #f69d3c;} to {border-radius: 50%; background: #0066ff} } </style> </head> <body> <h1>CSS animation-timing-function Property</h1> <div> Div </div> <button onclick="myFunction()">Click Me</button> <script> var x = document.getElementsByTagName("div")[0]; function myFunction(){ x.style.animation = "myAnimation 1s infinite"; x.style.WebkitAnimation = "myAnimation 1s infinite"; x.style.animationDirection = "alternate"; x.style.WebkitAnimationDirection = "alternate"; x.style.animationTimingFunction = "cubic-bezier(0.83, 2.3, 0.31, 0.46)"; x.style.WebkitAnimationTimingFunction = "cubic-bezier(0.83, 2.3, 0.31, 0.46)"; } </script> </body> </html>

Reminder

Hi Developers, we almost covered 98.7% of CSS Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in CSS.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author