InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

CSS animation

  • animation overview
  • animation-name
  • animation-duration
  • animation-timing-function
  • animation-delay
  • animation-iteration-count
  • animation-direction
  • animation-fill-mode
  • animation-play-state
  • animation shorthand
 
  • Home
  • > Tutorials
  • > CSS
  • > CSS properties
  • > CSS Animation

CSS3 animation overview

| Last updated on May 29, 2020

CSS property animation along with @keyframw definition can be used to implement animation on properties in CSS. The behaviour of these keyframe animations can be controlled by specifying their duration, number of repeats, and repeating behaviour.

@keyframes

@keyframes represent two or more waypoint in the animation. @keyframes specify values of animating properties.

Formal syntax

@keyframes <identifier> {
  [ [ from | to | <percentage> ] [, from | to | <percentage> ]* block ]*
}
Here are syntax examples defining @keyframes named left-to-right-to-left.

@keyframes left-to-right-to-left {
  0% {left:0;}
  50% {left:300px;}
  100% {left:0;}
}
// or 
@keyframes left-to-right-to-left {
  0%, 100% {left:0;}
  50% {left:300px;}
}
// or
@keyframes left-to-right-to-left {
  from {left:0;}
  50% {left:300px;}
  to {left:0;}
}

Note that from and to are alias for 0% and 100%.

Animation css properties

These are various animation properties which can either directly be specified or these can be specified using shorthand property animation.

Property Brief description
animation-name defines a list of animations that apply
animation-duration defines the length of time that an animation takes to complete one cycle. initial value is ‘0s’.
animation-timing-function describes how the animation will progress over one cycle of its duration. e.g. ‘ease’ (default), ‘linear’, etc.
animation-delay defines when the animation will start. Initial value is ‘0s’
animation-iteration-count specifies the number of times an animation cycle is played. initial value is ‘1’. ‘infinite’ will play it forever.
animation-direction defines whether or not the animation should play in reverse on some or all cycles. Initial value is ‘normal’.
animation-fill-mode defines what values are applied by the animation outside the time it is executing. Initial value is ‘none’
animation-play-state defines whether the animation is running or paused. Initial value is ‘running’.
animation (shorthand) animation-name || animation-duration || timing-function || animation-delay || animation-iteration-count || animation-direction || animation-fill-mode || animation-play-state (These should be in order)

Example – css basic left-to-right animation

In the following code, CSS property animation-duration can be changed to the following values
  • 4s
  • 8s
<style>
@keyframes left-to-right {
  0% {left:0;}
  60% {left:200px;}
  100% {left:300px;}
}
.box {
  position: fixed;
  background-color:lightgreen;
  animation-name: left-to-right;
  animation-duration:4s;
}
</style>

<div class=box>Object</div>
animation-duration refresh done
try it online

Example – css linear infinite iterations animation

Here animation shorhand is specifying animation name, duration, timeing-function, start delay and iteration-count.

<style>
@keyframes left-to-right {
  0% {left:0;}
  60% {left:200px;}
  100% {left:300px;}
}
.box {
  position: fixed;
  background-color:lightgreen;
  animation: left-to-right 4s linear 0s infinite;
}
</style>

<div class=box>Object</div>
refresh done
try it online

Specification and Browser compatibility

SpecificationStatusCategories
CSS AnimationW3C Working DraftCSS3
Desktop
ChromeFirefoxIEEdgeSafariOpera
Yes 43+ Yes 16+ Yes 10+ Yes 12+ Yes 9+ Yes 12.1+
Mobile
Android ChromeAndroid FirefoxiOS SafariIE MobileOpera Mobile
Yes 47+ Yes 44+ Yes 9.0-9.2+ Yes 10+ Yes 12.1+
source: caniuse.com

Suggested posts:

  1. CSS animation-name
  2. CSS animation-duration
  3. CSS text-transform – capitalize, uppercase and lowercase text
  4. CSS animation-iteration-count
  5. CSS animation-timing-function
  6. CSS animation-fill-mode
  7. CSS animation-direction
  8. CSS animation-delay
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged CSS, CSS Animation, CSS properties, Tutorials
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress