The Ultimate CSS Animation Properties Cheat Sheet

Introduction: What Are CSS Animations?

CSS animations allow web developers to create smooth, engaging transitions and movements without JavaScript or Flash. They enable elements to gradually change from one style to another, enhancing user experience and adding visual interest to web pages. CSS animations are:

  • Performance efficient – hardware-accelerated in modern browsers
  • Declarative – defined entirely in CSS without scripting
  • Customizable – with precise timing, duration, and behavior controls
  • Accessible – can respect user preferences for reduced motion

Core Animation Concepts

The Two Animation Systems in CSS

SystemBest ForControl Method
TransitionsSimple state changes, hover effectsProperty-based, triggered by state changes
Keyframe AnimationsComplex, multi-step animationsDefined sequences with precise control

CSS Transitions Properties

PropertyDescriptionExampleDefault
transition-propertySpecifies which CSS properties to animatetransform, opacityall
transition-durationDuration of the transition0.3s or 300ms0s
transition-timing-functionHow the animation progresses over timeease-in-outease
transition-delayDelay before animation starts0.5s or 500ms0s
transitionShorthand for all transition propertiesall 0.3s ease-in-out 0s

Timing Functions

FunctionDescriptionVisual Representation
linearConstant speedStraight line
easeSlow start, fast middle, slow endDefault, smooth curve
ease-inSlow start, then acceleratesGradual start
ease-outFast start, then deceleratesGradual end
ease-in-outSlow start and end, fast middleSymmetrical curve
cubic-bezier(n,n,n,n)Custom timing curveDefined by four control points
steps(n, start/end)Stepped transitionsDiscrete jumps

CSS @keyframes Animations

Basic Syntax

@keyframes animationName {
  from {
    /* starting styles */
  }
  to {
    /* ending styles */
  }
}

/* OR with percentage-based keyframes */
@keyframes animationName {
  0% {
    /* starting styles */
  }
  50% {
    /* middle styles */
  }
  100% {
    /* ending styles */
  }
}

Animation Properties

PropertyDescriptionExampleDefault
animation-nameName of the @keyframes animationfadeInnone
animation-durationDuration of the animation1s or 1000ms0s
animation-timing-functionHow the animation progresses over timeease-in-outease
animation-delayDelay before animation starts0.5s0s
animation-iteration-countNumber of times to play the animation3 or infinite1
animation-directionAnimation directionalternatenormal
animation-fill-modeStyle applied before/after animationforwardsnone
animation-play-statePauses or plays the animationpaused or runningrunning
animationShorthand for all animation propertiesfadeIn 1s ease-in-out 0s infinite alternate forwards

Animation Direction Values

ValueDescription
normalDefault – plays forward from 0% to 100%
reversePlays backwards from 100% to 0%
alternatePlays forward then backward
alternate-reversePlays backward then forward

Animation Fill Mode Values

ValueDescription
noneDefault – no styles applied before or after animation
forwardsElement retains the styles from the last keyframe
backwardsElement applies the styles from the first keyframe during delay period
bothCombines both forwards and backwards behavior

Step-by-Step: Creating CSS Animations

Method 1: Simple Transition

  1. Select the element with CSS
  2. Define its default state
  3. Define its changed state (e.g., on hover)
  4. Add transition properties to control the animation
.button {
  background-color: blue;
  transition: background-color 0.3s ease;
}

.button:hover {
  background-color: darkblue;
}

Method 2: Keyframe Animation

  1. Define the @keyframes animation sequence
  2. Select the element with CSS
  3. Apply the animation properties to the element
@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-20px);
  }
}

.bouncing-element {
  animation: bounce 1s ease infinite;
}

Animatable CSS Properties

Not all CSS properties can be animated. Here are the most commonly animated properties:

Transform Properties

  • transform: translate(x, y) – Move horizontally/vertically
  • transform: scale(x, y) – Resize horizontally/vertically
  • transform: rotate(deg) – Rotate by degrees
  • transform: skew(x-deg, y-deg) – Skew along X/Y axis

Visual Properties

  • opacity – Transparency
  • color – Text color
  • background-color – Background color
  • box-shadow – Shadow effects
  • border-color – Border color
  • border-width – Border width

Spatial Properties

  • width / height – Dimensions
  • margin / padding – Spacing
  • top / left / right / bottom – Positioning

Common Animation Challenges and Solutions

ChallengeSolution
Performance issues• Use transform and opacity when possible<br>• Add will-change property for complex animations<br>• Use translateZ(0) or translate3d(0,0,0) to trigger hardware acceleration
Animation not working• Check browser compatibility<br>• Verify property is animatable<br>• Ensure proper syntax in @keyframes<br>• Check if element is display: none
Flickering• Use backface-visibility: hidden<br>• Add transform-style: preserve-3d
Animations running on page load• Use animation-play-state<br>• Add animations with JavaScript after page load<br>• Use animation delay
Respecting reduced motion preferences• Use @media (prefers-reduced-motion)

Best Practices and Tips

Performance Optimization

  • Stick to transform and opacity for smooth animations (these don’t trigger layout)
  • Avoid animating layout properties (width, height, padding, margin) when possible
  • Use will-change sparingly to hint browser about properties that will animate
  • Limit the number of animated elements on screen at once

Code Organization

  • Name keyframes semantically based on their purpose (e.g., fadeIn, slideUp)
  • Use CSS variables for animation values that repeat or might change
  • Group related animations with similar timing or purpose

Accessibility

  • Always provide alternatives to motion-based interactions
  • Respect user preferences with prefers-reduced-motion media query:
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

Browser Compatibility

  • Use vendor prefixes or autoprefixer for older browsers
  • Test across browsers as animation support varies
  • Provide fallbacks for browsers without animation support

Common Animation Examples

Fade In

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.element {
  animation: fadeIn 1s ease-in-out;
}

Bounce

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-30px); }
  60% { transform: translateY(-15px); }
}

.element {
  animation: bounce 2s infinite;
}

Pulse

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.element {
  animation: pulse 2s infinite;
}

Spinner

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.spinner {
  animation: spin 1s linear infinite;
}

Resources for Further Learning

Documentation

Tools

Tutorials

Scroll to Top