Course contentsShow
← Web Development
Lesson 516 of 2,9829. CSS Transitions and AnimationsFree lesson

Keyframe Percentages

Define animation states at specific points using percentage-based keyframe selectors.

What You'll Learn

You'll learn how to define animation states at specific moments in time using percentage-based keyframe selectors inside @keyframes.


Understanding Keyframe Percentages

When you create animations with @keyframes, you're essentially building a timeline. Keyframe percentages let you specify exactly when during that timeline certain styles should apply.

Think of it like directing a short film:

  • At 0% (start): the actor is stage left
  • At 50% (halfway): the actor is center stage
  • At 100% (end): the actor is stage right

The browser smoothly animates between these waypoints.


How Keyframe Percentages Work

Inside your @keyframes rule, you use percentages as selectors to mark specific points in the animation timeline:

@keyframes slideAcross {
  0% {
    transform: translateX(0);
  }
  
  50% {
    transform: translateX(200px);
  }
  
  100% {
    transform: translateX(400px);
  }
}

In this example:

  • 0% = animation start (no movement)
  • 50% = halfway through the duration (moved 200px)
  • 100% = animation end (moved 400px)

You can use any percentage value from 0% to 100%, creating as many waypoints as needed:

@keyframes pulse {
  0% {
    opacity: 1;
  }
  
  25% {
    opacity: 0.7;
  }
  
  75% {
    opacity: 0.7;
  }
  
  100% {
    opacity: 1;
  }
}

This creates a pulse effect that dims, holds, then returns to full opacity.


Special Keywords

You can also use from (equivalent to 0%) and to (equivalent to 100%) for simple two-state animations, but percentages give you much more control over complex animation sequences.


Key Takeaway: Keyframe percentages divide your animation timeline into precise moments where you define specific styles, allowing the browser to smoothly interpolate between them to create fluid motion.