Creating Delightful, Performant UI Motion: Hover States, Keyframes, Shimmer & Tickers
CSS transitions interpolate between property values during state changes (e.g., :hover, :focus, :active, or class toggles).
/* Smooth button lift */
.btn {
transition: transform 0.25s ease, background-color 0.25s ease, box-shadow 0.25s ease;
}
.btn:hover {
transform: translateY(-4px) scale(1.02);
box-shadow: 0 8px 16px rgba(0,0,0,0.18);
}
@keyframes gives complete control over the intermediate steps of an animation sequence.
@keyframes float {
0%, 100% { transform: translateY(0px) rotate(-5deg); }
50% { transform: translateY(-18px) rotate(5deg); }
}
.floating-element {
animation: float 3s ease-in-out infinite;
}
Modern apps (YouTube, Facebook, LinkedIn) display pulsating shimmer gradients instead of static spinners while content loads.
@keyframes shimmer {
0% { background-position: -200% 0; }
100% { background-position: 200% 0; }
}
.skeleton {
background: linear-gradient(90deg, #e2e8f0 25%, #f8fafc 50%, #e2e8f0 75%);
background-size: 200% 100%;
animation: shimmer 1.5s infinite linear;
}
Seamless loops that add energy and character to headers and announcements.
/* Infinite horizontal ticker */
@keyframes marquee {
0% { transform: translateX(0%); }
100% { transform: translateX(-50%); }
}
.ticker {
display: inline-flex;
animation: marquee 12s linear infinite;
}
.ticker:hover {
animation-play-state: paused; /* Pause on mouse hover! */
}
Scroll-driven Animation: Look at the very top edge of your browser window — the gradient reading progress bar responds directly to your page scroll via animation-timeline: scroll(root block) with zero JavaScript!
Traditionally, transitioning from display: none to block was impossible without JS. Modern CSS solves this with @starting-style and allow-discrete!
pointer-events: none!
/* Scroll-driven progress bar */
.progress-bar {
animation: grow auto linear;
animation-timeline: scroll(root block); /* Native browser scroll timeline! */
}
/* Animate display: none using @starting-style */
.dialog {
transition: opacity 0.4s ease, display 0.4s allow-discrete;
}
@starting-style {
.dialog { opacity: 0; transform: translateY(-10px); }
}