CSS3 Keyframe Animations, Filters and Loaders: @keyframes, animation Properties, blur, drop-shadow and Respecting Reduced Motion
Transition vs Animation
| Transition | Animation | |
|---|---|---|
| Needs a trigger | Yes, like hover | No, can run alone |
| Steps | Start and end | Many steps with keyframes |
| Repeat | No | Yes |
Define and Use Keyframes
css
@keyframes fade-up {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.hero h1 {
animation: fade-up .8s ease-out both;
}
Shorthand: animation: name duration timing-function delay iteration-count direction fill-mode;
| Property | Meaning |
|---|---|
animation-name | Which @keyframes to run |
animation-duration | How long one cycle takes |
animation-iteration-count | How many times, or infinite |
animation-direction | normal, reverse, alternate |
animation-fill-mode | both keeps the first and last frames before and after |
animation-play-state | running or paused |
Multi-step Keyframes: A Pulse
css
@keyframes pulse {
0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(11, 95, 255, .5); }
70% { transform: scale(1.05); box-shadow: 0 0 0 14px rgba(11, 95, 255, 0); }
100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(11, 95, 255, 0); }
}
.cta { animation: pulse 2s infinite; }
A CSS Loading Spinner
html
<div class="spinner" role="status" aria-label="Loading"></div>
css
.spinner {
width: 40px; height: 40px;
border: 4px solid #d6e2ff;
border-top-color: #0b5fff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
Filters
css
img.gray { filter: grayscale(100%); transition: filter .3s; }
img.gray:hover { filter: none; }
.glass { backdrop-filter: blur(8px); background: rgba(255, 255, 255, .5); }
.shadowed { filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .3)); }
.dim { filter: brightness(.8) contrast(1.1); }
| Filter | Effect |
|---|---|
blur(px) | Soften |
grayscale(%) | Remove color |
brightness(n) | Lighter or darker |
drop-shadow() | Shadow that follows the shape, even for transparent PNGs and SVG |
Be Kind to People: Reduced Motion
css
@media (prefers-reduced-motion: reduce) {
.cta, .hero h1 { animation: none; }
.spinner { animation-duration: 3s; }
}
Avoid flashing Never flash content more than three times per second. It can be dangerous for some people. Do not make important information appear only inside an animation.
Practice
- Fade and slide in a heading on page load
- Build a spinner and a pulsing button
- Make a photo gray until hover
Conclusion
Keyframes run multi-step animations by themselves. Use animation properties, filters and always respect reduced motion.
Quick Summary: Transition vs animation; keyframes; pulse; spinner; filters; reduced motion.

