Skip to main content

CSS animation-delay Property

To make an animation wait before it begins, give animation-delay a time value.

A negative value works too, and it has the opposite feel: the animation begins as though that much of it had already played.

Example

Here the animation waits 2 seconds before it starts to play:

Prompt
Create a page showing a red 100x100px div that uses CSS animation to move from left to right. Set animation-delay to 2 seconds so the animation starts after a 2 second pause. Use @keyframes to move the div from left:0px to left:250px.
Output: complete HTML page

Negative delay

Playback begins partway in, as though 2 seconds of it had already gone by:

Prompt
Create a page showing a red 100x100px div that uses CSS animation to move from left to right. Set animation-delay to -2s so the animation starts as if it had already been playing for 2 seconds. Use a 4 second animation-duration and @keyframes to move from left:0px to left:250px.
Output: complete HTML page

CSS animation-iteration-count Property

How many times an animation runs is controlled by animation-iteration-count.

Example

Here the animation plays through three times, and then it stops:

Prompt
Create a page showing a red 100x100px div that uses CSS animation to move from left to right. Set animation-iteration-count to 3 so the animation runs 3 times. Use @keyframes to move the div from left:0px to left:250px with a 4 second duration.
Output: complete HTML page

Infinite iteration

Setting the value to infinite keeps the animation going forever:

Prompt
Create a page showing a red 100x100px div that uses CSS animation to move from left to right forever. Set animation-iteration-count to infinite. Use @keyframes to move the div from left:0px to left:250px with a 4 second duration.
Output: complete HTML page

CSS animation-timing-function Property

An animation's speed curve comes from animation-timing-function, which accepts these values:

  • ease - the default: a slow start, then fast, then a slow finish
  • linear - runs at one constant speed throughout
  • ease-in - begins slowly
  • ease-out - finishes slowly
  • ease-in-out - begins and finishes slowly
  • cubic-bezier(n,n,n,n) - your own values, supplied in a cubic-bezier function

Example

A few of the available speed curves appear below:

Prompt
Create a page with five red 100x100px divs stacked vertically, each showing a different animation-timing-function value: linear, ease, ease-in, ease-out, and ease-in-out. All divs animate from left:0px to left:250px with a 4 second duration and infinite iteration count. Label each div with its timing function name.
Output: complete HTML page