DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
← From Beginner to Expert in Fundamentals of Frontend
  • The Box Model
  • Specificity & The Cascade
  • CSS Units Deep Dive
  • Stacking Contexts & Z-Index
  • Flexbox Mastery
  • CSS Grid Mastery
  • Centering, Subgrid & Container Queries
  • CSS Custom Properties & Variables
  • Selectors: :has(), Pseudo-classes & Pseudo-elements
  • Responsive Functions: calc(), clamp(), min(), max()
  • Media Queries & Mobile-First Design
  • Transitions & Animations
  • Transforms, Filters & Clipping
  • CSS Methodologies: BEM, CSS-in-JS & Tailwind
  • Typography, Color Spaces & Dark Mode
  • CSS Performance & Optimization
  • CSS Interview Questions — Part 1
  • CSS Interview Questions — Part 2
← From Beginner to Expert in Fundamentals of Frontend

Transitions & Animations

20 min read
TransitionsKeyframe Animationscubic-bezierGPU Accelerationtransformopacityanimation-fill-modeprefers-reduced-motion

Bringing CSS to Life

Transitions vs Animations

FeatureTransitionsAnimations
Triggered byState change (hover, class toggle)Automatic or triggered
KeyframesStart and end onlyMultiple steps
RepeatOnly on triggerCan loop infinitely
DirectionForward on trigger, reverse on un-triggerNormal, reverse, alternate
JavaScript neededOnly to toggle class/stateCan run without JS

GPU-Accelerated Properties

Only these properties can be animated on the compositor thread (GPU) without triggering layout or paint:

PropertyGPU Accelerated?Performance
transform✅ Yes🟢 Excellent
opacity✅ Yes🟢 Excellent
filter✅ Yes (mostly)🟡 Good
width / height❌ No🔴 Causes reflow
top / left❌ No🔴 Causes reflow
margin / padding❌ No🔴 Causes reflow
background-color❌ No🟡 Causes repaint

Timing Functions

Keywordcubic-bezierFeel
easecubic-bezier(0.25, 0.1, 0.25, 1)Natural, starts fast, slows down
ease-incubic-bezier(0.42, 0, 1, 1)Accelerates (entering)
ease-outcubic-bezier(0, 0, 0.58, 1)Decelerates (exiting)
ease-in-outcubic-bezier(0.42, 0, 0.58, 1)Slow start and end
linearcubic-bezier(0, 0, 1, 1)Constant speed (robotic)

The animation-fill-mode Property

ValueBefore AnimationAfter Animation
noneOriginal stylesReverts to original
forwardsOriginal stylesKeeps final keyframe ✅
backwardsUses first keyframeReverts to original
bothUses first keyframeKeeps final keyframe ✅

Reduced Motion

Always respect users who prefer reduced motion (vestibular disorders, motion sensitivity):

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.