Nearby lessons

8 of 15

🎬 CSS Animations

📌 What are CSS Animations?

CSS animations allow you to create engaging visual transitions between style states using @keyframes and animation properties — no JavaScript needed!

📽️ Introduction to CSS Animations

CSS animations let you:

  • Create smooth transitions between CSS property values
  • Control timing, duration, and repetition
  • Avoid JavaScript for simple animations
  • Optimize performance, especially on mobile

📉 Animation Syntax - 1 : from to

Define an animation by setting the starting and ending values of properties.

@keyframes example {
from { CSS Properties }
to { CSS Properties }
}

📊 Animation Syntax - 2 : Percentage Syntax

Use percentage values to define multiple steps of an animation timeline.

@keyframes example {
0% { CSS Properties }
50% { CSS Properties }
100% { CSS Properties }
}

🛠️ Border Radius Animation

Demonstrates smooth border-radius animation from square to circle.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

🌈 Color Change Animation

This animation transitions the background color through multiple colors.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

🏀 Bounce Animation

This animation makes an element bounce vertically using the transform property.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

🏀 Animation Timing Function Values

Demonstrates different animation-timing-function values like linear, ease, ease-in, ease-out, and ease-in-out.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

✅ Best Practices for CSS Animations

  • ⚡ Prefer animating transform and opacity for performance
  • 👀 Avoid overusing animations — keep them subtle
  • 🎚️ Use prefers-reduced-motion to respect user settings
  • ⏱️ Stick to 200–500ms durations for good UX
  • 📱 Test performance, especially on mobile devices

📘 CSS Animation Properties

AttributeDescription
animationShorthand for all animation properties
animation-nameName of the @keyframes animation
animation-durationTime to complete one cycle (e.g., 2s, 500ms)
animation-timing-functionSpeed curve of the animation (e.g., ease, linear)
animation-delayDelay before animation starts
animation-iteration-countNumber of times the animation repeats
animation-directionWhether animation reverses (e.g., alternate)
animation-fill-modeApplies styles before/after animation (e.g., both)
animation-play-stateRunning or paused animation state

🧠 Test Your Knowledge

5 Questions

Progress: 0 / 5
Keep Going!CSS - Transitions