Keyframes, transitions, transforms, and animation properties
Shorthand for all transition properties
transition: all 0.3s ease;
Specify which properties to animate
transition-property: transform, opacity;
How long the transition takes
transition-duration: 0.3s;
How the transition progresses over time
transition-timing-function: ease-in-out;
Delay before transition starts
transition-delay: 0.1s;
Apply 2D or 3D transformations
transform: translateX(10px) rotate(45deg);
Move element in 2D space
transform: translate(10px, 20px);
Move element along specific axis
transform: translateX(10px);
Scale element size
transform: scale(1.2);
Rotate element
transform: rotate(45deg);
Skew element
transform: skew(10deg, 5deg);
Define custom animation sequence
@keyframes slideIn {
from { transform: translateX(-100%); }
to { transform: translateX(0); }
}
Shorthand for all animation properties
animation: slideIn 0.5s ease-out;
Name of the keyframe animation
animation-name: slideIn;
How long the animation takes
animation-duration: 0.5s;
How the animation progresses
animation-timing-function: ease-out;
Delay before animation starts
animation-delay: 0.2s;
How many times to repeat
animation-iteration-count: infinite;
Direction of animation
animation-direction: alternate;
Styles before/after animation
animation-fill-mode: forwards;
Slow start, fast middle, slow end
transition-timing-function: ease;
Constant speed
transition-timing-function: linear;
Slow start, fast end
transition-timing-function: ease-in;
Fast start, slow end
transition-timing-function: ease-out;
Slow start and end, fast middle
transition-timing-function: ease-in-out;
Custom timing function
transition-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94);
Common hover animations
.button {
background: #007bff;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
transition: all 0.3s ease;
}
.button:hover {
background: #0056b3;
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
Simple fade in effect
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.fade-in {
animation: fadeIn 0.6s ease-out;
}
Rotating loading animation
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.spinner {
width: 40px;
height: 40px;
border: 4px solid #f3f3f3;
border-top: 4px solid #3498db;
border-radius: 50%;
animation: spin 1s linear infinite;
}
Slide animation for content
@keyframes slideInLeft {
from {
transform: translateX(-100%);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
.slide-in {
animation: slideInLeft 0.5s ease-out;
}
Pulsing animation for attention
@keyframes pulse {
0% {
transform: scale(1);
}
50% {
transform: scale(1.05);
}
100% {
transform: scale(1);
}
}
.pulse {
animation: pulse 2s infinite;
}
Use transform
instead of changing layout properties for better performance
Keep animations under 300ms for smooth user experience
Use will-change
property for elements that will animate
Respect prefers-reduced-motion
for accessibility
Use animation-fill-mode: forwards
to maintain final state