</> Code Corner

CSS · CSS Advanced · Lesson 50

CSS Animations

@keyframes and animation properties.

CSS animations let an element gradually change from one style to another, as many times as you want, without JavaScript.

Example

<style>
@keyframes slide {
  0%   { background: tomato; left: 0; }
  50%  { background: gold; left: 200px; }
  100% { background: #04AA6D; left: 0; }
}
.ball {
  position: relative; width: 60px; height: 60px; border-radius: 50%;
  animation: slide 3s ease-in-out infinite;
}
</style>
<div class="ball"></div>
Property Use
@keyframes Defines the styles at each step
animation-name / duration Which keyframes and how long
animation-iteration-count Number of runs, or infinite
animation-direction normal, reverse, alternate
animation-delay / timing-function Delay and speed curve

Keep reading “CSS Animations”

Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.

Chat with us 👋