Skip to content
CSS3

Animations

Define keyframes and apply reusable animations.

By EZ4Code Team
animationskeyframes

Code

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-30px); }
}

.ball {
  animation: bounce 1s ease-in-out infinite;
  animation-name: bounce;
  animation-duration: 1s;
  animation-iteration-count: infinite;
  animation-direction: alternate;
}

/* Pause on hover */
.ball:hover {
  animation-play-state: paused;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.fade { animation: fade-in 0.5s ease forwards; }

Explanation

@keyframes define intermediate states of an animation as percentages from 0% to 100%. The animation shorthand sets duration, timing, iteration count, and direction in one declaration. Use animation-play-state to pause or resume, and forwards to retain the end state.

More CSS3 Snippets