CSS Keyframe Animations

Create smooth keyframe animations with transform and opacity for performing transitions without layout thrashing.

CssData Fetching

Code

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade {
  animation: fadeIn 0.3s ease-out forwards;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

CSS Keyframe Animations

Create smooth keyframe animations with transform and opacity for performing transitions without layout thrashing.

Code

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade {
  animation: fadeIn 0.3s ease-out forwards;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

Explanation

Two keyframes drive the compositor: fadeIn translates and fades an element in over 0.3s, while pulse scales it between 1 and 1.05 on a loop. Expected behavior: the animated element holds its final state because fadeIn uses forwards. Limitation: only transform and opacity stay cheap to animate; animating layout properties such as width or top forces reflow.

Interactive Tools for This Topic