Keyframe Animations

@keyframes

Keyframe animations run on their own (no hover needed) and can have many steps:

@keyframes name {
  from { ... }   /* or 0% */
  50%  { ... }
  to   { ... }   /* or 100% */
}
.element { animation: name 2s ease-in-out infinite; }

Example

Example

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    @keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }
    @keyframes spin { to { transform: rotate(360deg); } }
    @keyframes slide { from { transform: translateX(-100%); opacity: 0; } to { transform: none; opacity: 1; } }
    .heart { display: inline-block; font-size: 40px; animation: pulse 1s ease-in-out infinite; }
    .spinner { width: 34px; height: 34px; border: 4px solid #ddd; border-top-color: #04AA6D; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; margin-left: 30px; }
    .toast { margin-top: 14px; background: #282A35; color: white; padding: 10px; font-family: Arial; width: 220px; animation: slide .6s ease-out both; }
  </style>
</head>
<body>

<span class="heart">❤</span><span class="spinner"></span>
<div class="toast">Slides in once on load</div>

</body>
</html>

Result

Respect Reduced Motion

Some users get dizzy from motion and turn it off in their operating system. Honour that setting:

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}