ANIMATIONS

ADVANCED CSS ANIMATIONS

BRING YOUR CONTENT TO LIFE.

WHAT IS IT?

CSS animations let you animate from one style to another. Like traditional animation, keyframes are utilized and can be used to manipulate properties such as transformations, transitions, timing, repeats, and more.

WHY USE IT?

Well done animations can enhance the user experience and add character to a website. It can be a powerful tool to draw attention to certain content and elicit greater emotional responses from users.

BASICS

THE BASICS

Building the foundation.

KEYFRAMES

Keyframes form the foundation to creating CSS animations, defining what the timeline of the animation will look like.

PROPERTIES

Properties assign keyframes to elements and define how they are animated. The two essential properties for an animation to function are animation-name and animation-duration.

animation-name

defines the name of the animation.

animation-duration

defines the duration of the animation, in seconds or milliseconds.

div {animation-name: name; animation-duration: 5s;}

@keyframes

uses the values to and from, as well as percentages to define keyframes.

@keyframes name {from {background-color: red;} to {background-color: yellow;}}

@keyframes name {0% {background-color: red;} 50% (background-color: green;} 100% {background-color: yellow;}}

note: if no duration is specified, the animation will have no effect.

note: it is good practice to use prefixes (-moz- and -webkit-) to ensure animations function across browsers.

PROPERTIES

PROPERTIES

Values and defining the animation.

The following are properties and the values applied to elements. Hover over the shapes to see how they work.

animation-delay

specifies a delay for the animation, in seconds or milliseconds.

animation-direction

specifies if animation plays forward, reverse, or in alternate cycles.

normal

animation plays forward (default)

reverse

animation plays backwards

alternate

animation reverses direction every cycle, playing forward on odd cycles and backwards on even cycles

alternate-reverse

animation reverses direction every cycle, playing backwards on odd cycles and forward on even cycles

animation-fill-mode

specifies if the animation styles are visible before or after the animation plays.

none

the animation does not apply any styles to the element, before or after the animation

backwards

before the animation, the styles of the initial keyframe are applied to the elements

forwards

after the animation, the styles in the final keyframe are retained by the element

both

the animation follows both the backwards and forwards rule, extending the animation properties before and after the animation

animation-iteration-count

specifies the number of times an animation runs.

initial

sets the iteration count to default value

number

specifies a number (default is 1), in this case, 3

infinite

animation repeats forever

inherit

inherits the value from the parent

animation-play-state

specifies whether the animation is playing or paused, a paused animation starts where it left off.

running

the animation is currently running

paused

the animation is currently paused

animation-timing-function

specifies the speed curve of the animation.

ease

slow start, then fast, then slow end (default)

linear

same speed from start to end

ease-out

slow end

ease-in

slow start

ease-in-out

slow start and end

cubic-bezier(n,n,n,n)

define your own values in a cubic-bezier function