CSS Animations Tutorial

Create stunning animations for web elements using CSS keyframes, optimized for all screen sizes.

Master CSS Animations

CSS animations add life to websites with smooth, engaging effects. This 2025 tutorial teaches you six unique animations using @keyframes, from fading text to bouncing balls. All examples run in the browser and are optimized for small outputs, perfect for beginners and web designers.

Why Learn CSS Animations?

Animations enhance user engagement and make interfaces stand out. This tutorial covers:

  • Creating animations with @keyframes and animation properties.
  • Animating text, shapes, and backgrounds.
  • Adding interactivity with JavaScript for toggling animations.
  • Optimizing for performance and accessibility.

Best Practices

Use transform and opacity for efficient animations. Keep durations short (1–3s), test across devices, and respect prefers-reduced-motion for accessibility. Avoid heavy CSS properties like width or height.

Example 1: Fading Text Animation

This example animates text to fade in and out using opacity. It’s simple and looks great in small iframes.

Code Editor
Download Code
Live Output

Note: Edit the text or animation duration. The fade effect is smooth and works well in small outputs. Test with prefers-reduced-motion for accessibility.

Example 2: Rotating Square Animation

This example rotates a square continuously using transform. It’s simple and scales well in small iframes.

Code Editor
Download Code
Live Output

Note: Adjust the square’s size or rotation speed. The animation is smooth and visible in small outputs.

Example 3: Scaling Circle Animation

This example animates a circle to grow and shrink using transform: scale. Perfect for small screens.

Code Editor
Download Code
Live Output

Note: Change the circle’s color or scale factor. The animation is lightweight and clear in small outputs.

Example 4: Sliding Line Animation

This example animates a horizontal line sliding left to right using transform: translateX.

Code Editor
Download Code
Live Output

Note: Modify the line’s width or animation distance. The sliding effect is clear and effective in small outputs.

Example 5: Color-Changing Background

This example animates a div’s background color through multiple hues using background-color.

Code Editor
Download Code
Live Output

Note: Customize the colors or timing in @keyframes. The color transition is vibrant and clear in small outputs.

Example 6: Bouncing Ball Animation

This example animates a ball bouncing up and down, with a JavaScript toggle for interactivity. It’s optimized for small screens.

Code Editor
Download Code
Live Output

Note: Click the toggle button to pause/resume the animation. Adjust the bounce height or speed. The effect is clear in small outputs.

Next Steps

Experiment with other properties like box-shadow or border-radius. Try combining animations or adding CSS transitions. Explore Webshs Tutorials for Web Development, Android Apps, or Data Science, or see Button Animations for more UI ideas.