CSS Animation Magic ✨
CSS Animation Magic ✨
Animations bring websites to life! Let's explore how to create beautiful CSS animations.
Why Animations Matter
Good animations can:
- Improve user experience
- Guide user attention
- Make interfaces feel more responsive
- Add personality to your brand
Basic Animation Properties
Keyframes
Define your animation using @keyframes:
@keyframes float {
0%, 100% {
transform: translateY(0px);
}
50% {
transform: translateY(-20px);
}
}
Applying Animations
.floating-element {
animation: float 3s ease-in-out infinite;
}
Advanced Techniques
Stagger Animation
.item:nth-child(1) { animation-delay: 0s; }
.item:nth-child(2) { animation-delay: 0.1s; }
.item:nth-child(3) { animation-delay: 0.2s; }
Hover Effects
.button {
transition: all 0.3s ease;
}
.button:hover {
transform: scale(1.05);
box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
Performance Tips
- Use
transformandopacityfor better performance - Avoid animating
width,height, ormargin - Use
will-changesparingly - Keep animations under 300ms for UI feedback
Example: Card Hover Effect
.card {
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.card:hover {
transform: translateY(-10px);
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
}
Resources
- CSS Tricks - Animation
- MDN Web Docs
- Animista - CSS animation library
Start experimenting with animations today! 🎨