CSS - Animations Part 1

Jun 25, 2026 3:00pm UTC (Check your timezone)

Theory Workshop Lab

Instructors: Jess, Carmen, and Eda

Animations

Download iCal File

Before this session, please:

During this session, we’ll:

After this session, please:

Instructor notes

Animations and Accessibility: What Are CSS Animations, and How Do They Work?

A CSS animation essentially has two components:

The @keyframes rule defines what styles an element has at different stages of the animation.

For example, a @keyframes rule named slide-in to go from left to right can be defined like this:

1@keyframes slide-in {
2  0% {
3    transform: translateX(-100%);
4  }
5  100% {
6    transform: translateX(0);
7  }
8}

0% is the start of the animation, and 100% is the end. With transform property with the values for translateX, specifies the horizontal position of the element.

Once we defined the animation, we can actually apply it to the element:

1<div class="sliding-element">Hello!</div>
1.sliding-element {
2  animation: slide-in 2s ease-out infinite;
3}

The animation property is a shorthand for:

Another example to change the background color of an element, with explicitly written properties:

1<div class="traffic-lights"></div>
 1.traffic-lights {
 2  width: 200px;
 3  height: 200px;
 4  padding: 1rem;
 5  border: 4px solid black;
 6  border-radius: 50%;
 7  animation-name: color-change;
 8  animation-duration: 5s;
 9  animation-timing-function: linear;
10  animation-delay: 1s;
11  animation-iteration-count: infinite;
12  animation-direction: alternate;
13}
14
15@keyframes color-change {
16  0% {
17    background-color: red;
18  }
19  50% {
20    background-color: orange;
21  }
22  100% {
23    background-color: limegreen;
24  }
25}

It looks like this:

We should, however, avoid overusing animations, as it can lead to performance and accessibility issues. While designing our websites, we should always provide options to reduce or disable animations.

Animations and Accessibility: What Are Accessibility Concerns Around Using Animations, and How Can prefers-reduced-motion Help?

Using animations can create accessibility issues. For example, certain types of movement on screen can cause dizziness, nausea, and headaches for people with vestibular disorders or motion sensitivity.

It can also be distracting for people with cognitive disabilities and make it hard to focus on the content. Even more, rapid flashing and certain effects can trigger seizures in people with photosensitive epilepsy. A general rule is to avoid content that flashes more than three times per second.

A user can request minimal animations or motion effects at the system level in the settings of their device. To write CSS respecting this setting, we can use the prefers-reduced-motion media query:

1@media (prefers-reduced-motion: reduce) {
2  * {
3    animation-duration: 0.01ms !important;
4    animation-iteration-count: 1 !important;
5    transition-duration: 0.01ms !important;
6    scroll-behavior: auto !important;
7  }
8}

The example above minimizes the animations but doesn’t completely stop them. To do that, the animation can be set to none:

1.animated-element {
2  transition: transform 0.3s ease-in-out;
3}
4
5@media (prefers-reduced-motion: reduce) {
6  .animated-element {
7    transition: none;
8  }
9}

Build an Animated Ferris Wheel

We’ll take a look at this exercise that goes over some HTML and CSS animations!

Build a Moon Orbit

This fun exercise lets you create a simple animation of the Moon’s orbit around the Earth using HTML and CSS!