Free Ebook cover Complete CSS course

Complete CSS course

4.5

(2)

35 pages

CSS animations

Capítulo 25

Estimated reading time: 2 minutes

Audio Icon

Listen in audio

0:00 / 0:00

Animations in CSS

CSS animations are a way to add movement and interactivity to elements on a web page. With them, you can create amazing visual effects and bring static layout elements to life.

CSS properties for animations

To create animations in CSS, you need to use some specific properties. The main ones are:

  • @keyframes: defines the animation itself, specifying the initial and final states of the elements;
  • animation-name: defines the name of the animation;
  • animation-duration: sets the duration of the animation;
  • animation-timing-function: defines the type of animation, such as linear, ease-in, ease-out, ease-in-out, among others;
  • animation-delay: sets the delay time before the animation starts;
  • animation-iteration-count: defines the number of times the animation will be played;
  • animation-direction: defines the animation direction, such as normal, reverse, alternate, alternate-reverse, among others.

CSS animation example

Let's create a simple CSS animation example to better understand how it works:

  
    /* Defining the animation */
    @keyframes move {
      0% { transform: translateX(0); }
      50% { transform: translateX(50px); }
      100% { transform: translateX(0); }
    }

    /* Applying the animation */
    .element {
      animation-name: move;
      animation-duration: 2s;
      animation-timing-function: ease-in-out;
      animation-iteration-count: infinite;
    }
  

In this example, we create an animation called "move" that causes an element to move to the right and back to its starting position. For that, we use the transform: translateX() property to change the horizontal position of the element.

We then apply animation to the element using the animation-name, animation-duration, animation-timing-function and animation-iteration-count properties.

Continue in our app.

You can listen to the audiobook with the screen off, receive a free certificate for this course, and also have access to 5,000 other free online courses.

Or continue reading below...
Download App

Download the app

Conclusion

CSS animations are a great way to add interactivity and dynamism to web pages. With the right properties and a little creativity, you can create amazing effects that will blow your mind.

Now answer the exercise about the content:

_What is the CSS property that defines the duration of the animation?

You are right! Congratulations, now go to the next page

You missed! Try again.

The CSS property that sets the duration of the animation is animation-duration. This property determines how long the animation will take to complete one cycle.

Next chapter

Transitions in CSS

Arrow Right Icon
Download the app to earn free Certification and listen to the courses in the background, even with the screen off.