CSS Easing Functions

Master the art of smooth web animations with built-in keywords, custom cubic-bezier curves, and step functions that bring your interfaces to life.

What Are CSS Easing Functions?

CSS easing functions are essential tools for creating polished, professional animations in web applications. They control the rate of change of animated values, making transitions feel natural and engaging rather than robotic and abrupt.

The CSS easing functions module defines three main types of easing functions: linear, cubic-bezier, and step easing functions according to MDN Web Docs. Each type serves different purposes and creates distinct visual effects that can dramatically impact user perception of your interface.

In modern web development, well-crafted animations do more than add visual appeal--they provide crucial user feedback, guide attention, and create memorable interactions. Understanding easing functions is fundamental to creating interfaces that feel polished and professional. Whether you're animating a simple button hover or building complex microinteractions, the right easing function makes the difference between an animation that feels natural and one that feels jarring.

Related concepts include CSS transforms for movement and scaling, CSS nesting for organized stylesheets, and CSS value functions that work alongside easing to create sophisticated animations in your web applications.

Built-In Easing Keywords

CSS provides five built-in easing keywords that cover the most common animation patterns. These keywords are widely supported across all browsers and provide a quick way to add polish to your animations without any additional configuration.

The linear Keyword

The linear keyword produces an animation that progresses at a constant speed from start to finish. While this might seem undesirable at first, there are specific use cases where linear easing works best. Continuous animations like spinning loaders, progress indicators, and some types of scrolling effects benefit from linear timing because they maintain consistent motion throughout.

Behind the scenes, linear is equivalent to cubic-bezier(0, 0, 1, 1), which represents a straight line from the start point (0, 0) to the endpoint (1, 1) of the animation timeline according to W3Schools.

The ease Keyword

The ease keyword is the most commonly used easing function and provides a gentle acceleration at the start and deceleration at the end of the animation. This creates a natural "ease-in-out" effect that feels smooth and organic. It's the default easing applied to many browser transitions and works well for most UI animations.

The ease keyword corresponds to cubic-bezier(0.25, 0.1, 0.25, 1), which creates a subtle S-curve that accelerates moderately at the start and decelerates smoothly at the end according to MDN Web Docs.

The ease-in Keyword

The ease-in keyword starts animations slowly and accelerates toward the end, creating an effect where the element appears to "build up speed" as it animates. This easing works well for elements that are leaving the viewport, such as modals closing, menus collapsing, or elements being removed from the DOM.

The ease-in function maps to cubic-bezier(0.42, 0, 1, 1), where the animation spends most of its time in the initial slow phase and quickly completes the final portion according to MDN Web Docs.

The ease-out Keyword

The opposite of ease-in, ease-out begins quickly and decelerates smoothly to a stop. This creates an effect where elements appear to "settle into place," making it ideal for elements entering the viewport. Modal windows appearing, dropdowns expanding, and tooltip animations all benefit from ease-out.

This easing corresponds to cubic-bezier(0, 0, 0.58, 1), with most of the animation completing quickly and a longer deceleration phase at the end according to MDN Web Docs.

The ease-in-out Keyword

The ease-in-out keyword combines ease-in and ease-out for animations that start slow, accelerate through the middle, and slow down again at the end. This creates the most dramatic S-curve and works well for elements that need to feel like they're being pulled by both ends.

The mathematical representation is cubic-bezier(0.42, 0, 0.58, 1), providing the smoothest transitions for elements that appear to have mass and momentum according to MDN Web Docs.

Built-in Easing Keywords
1/* Built-in easing keyword examples */2.linear {3 animation: spin 1s linear infinite;4}5 6.ease {7 transition: transform 0.3s ease;8}9 10.ease-in {11 animation: slideOut 0.5s ease-in forwards;12}13 14.ease-out {15 animation: slideIn 0.3s ease-out forwards;16}17 18.ease-in-out {19 animation: fadeSlide 0.4s ease-in-out forwards;20}

Custom Easing with cubic-bezier()

The real power of CSS easing comes from the cubic-bezier() function, which allows you to define custom easing curves beyond the five built-in keywords. This function accepts four parameters representing two control points that define the shape of the easing curve.

Understanding the Syntax

The cubic-bezier function is defined by four numbers: cubic-bezier(x1, y1, x2, y2). These values represent two control points (P1 and P2) of a cubic Bézier curve, while the start point (P0) is fixed at (0, 0) and the end point (P3) is fixed at (1, 1) according to CSS-Tricks. The x-axis represents time (progress from 0 to 1), while the y-axis represents the output value.

By manipulating the control points, you can create easing functions that go beyond the standard ease-in and ease-out patterns. Control points can even have y-values outside the [0, 1] range, which creates "bounce" effects where the animation temporarily overshoots its target and returns according to MDN Web Docs.

Creating Custom Easing Curves

One powerful technique is to create easing functions that are faster than linear at certain points. For example, cubic-bezier(0.8, 0, 1, 0.2) creates an easing function that starts slowly but accelerates quickly through the middle portion, useful for elements that need to move decisively across the screen.

Bounce and Elastic Effects

One of the most exciting possibilities with cubic-bezier() is creating bounce effects by allowing the y-values of control points to exceed the normal [0, 1] range. When a control point's y-value is greater than 1, the animation temporarily overshoots its target before returning, creating a bounce or elastic effect according to CSS-Tricks.

Values like cubic-bezier(0.175, 0.885, 0.32, 1.275) create noticeable bounce effects. The first two values control the ease-in portion, while the final value causes the animation to overshoot past the target before settling.

For advanced animation techniques, consider combining cubic-bezier with CSS transforms to create sophisticated motion effects, and explore CSS motion path for more complex animations in your UI/UX design projects.

Custom cubic-bezier Easing Functions
1/* Custom cubic-bezier examples */2.bounce {3 animation: bounce 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;4}5 6.snappy {7 animation: slideIn 0.4s cubic-bezier(0.8, 0, 1, 0.2) forwards;8}9 10.smooth-entrance {11 animation: fadeIn 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;12}13 14/* Combining multiple animations with different easings */15.complex-animation {16 animation:17 slideIn 0.6s cubic-bezier(0.25, 1, 0.5, 1) forwards,18 fadeIn 0.4s ease-out forwards;19}

Step Easing Functions

Step easing functions create animations that progress in discrete jumps rather than smooth transitions. This creates a mechanical, frame-by-frame appearance that can evoke retro aesthetics or draw attention through visible state changes.

The steps() Function Syntax

The accepts two parameters: the number of steps steps() function and an optional direction keyword. The syntax is steps(number_of_steps, direction). The direction can be start, end, or jump-start, jump-end, jump-none, jump-both for more precise control according to MDN Web Docs.

Start vs End Direction

The start direction causes the first jump to occur immediately at the start of the animation, while end delays the first jump until the animation is 1/n through its duration according to MDN Web Docs. This subtle difference affects the timing of when jumps occur relative to the animation's start and end.

For a 5-step animation over 1 second, steps(5, start) would show the first state immediately at time 0, while steps(5, end) would wait until 0.2 seconds to show the first state.

Practical Applications

Step animations are perfect for creating countdown timers, sequential displays, and retro-style interfaces. They also work well for progress indicators where you want discrete chunks rather than smooth transitions according to W3Schools. This technique animates through a sprite sheet by changing background position in discrete steps.

Step animations work particularly well for progress indicators and loading states in web applications, providing users with clear, discrete feedback about ongoing processes. For creating visual interest, consider pairing step animations with basic CSS shapes for retro-style effects.

Step Easing Functions
1/* Step easing examples */2.frame-by-frame {3 animation: frames 2s steps(8) infinite;4 background-image: url("sprite-sheet.png");5 background-position: 0 0;6 background-size: 800% 100%;7}8 9@keyframes frames {10 100% { background-position: 100% 0; }11}12 13/* Progress with discrete steps */14.progress {15 animation: load 10s steps(10) forwards;16}17 18@keyframes load {19 from { width: 0; }20 to { width: 100%; }21}22 23/* Start vs End comparison */24.step-start {25 transition: transform 1s steps(5, start);26}27 28.step-end {29 transition: transform 1s steps(5, end);30}

Performance Best Practices

While CSS animations are generally performant, understanding how easing functions impact performance helps you create smoother, more efficient animations.

Hardware Acceleration

Simple property animations using transforms and opacity are typically hardware-accelerated, meaning the GPU handles the rendering. Easing functions don't significantly impact performance for these properties because the browser can optimize the animation calculations according to MDN Web Docs. Complex cubic-bezier functions with extreme values don't slow down the animation--the calculation is still just four numbers, regardless of their values.

However, animating properties that trigger layout changes (like width, height, or margin) is more expensive and can cause janky animations. Always prefer transforming and opacity-based animations when possible, regardless of which easing function you choose.

Reduced Motion Preference

Modern CSS supports the prefers-reduced-motion media query, which detects whether the user has requested reduced motion in their system settings. Respecting this preference is essential for accessibility, as many users experience discomfort or motion sickness from animations according to MDN Web Docs.

Animation Timing Considerations

The duration of your animation interacts with your easing function to create the overall experience. A subtle ease-out over 0.2 seconds feels snappy and responsive, while the same easing over 1 second feels leisurely and smooth. Matching animation duration to the easing function's character is crucial--fast animations suit snappy easings, while elaborate entrance animations benefit from gentler easings and longer durations.

For optimal performance in your full-stack web applications, always test animations on actual devices and consider the user's device capabilities when choosing animation complexity. Pairing these techniques with CSS scoping helps maintain clean, performant stylesheets.

Performance Best Practices
1/* Performance-optimized animations */2.animated-element {3 /* Use transform and opacity for GPU acceleration */4 transform: translateX(0);5 opacity: 1;6 transition: transform 0.3s ease-out, opacity 0.3s ease-out;7}8 9/* Respect reduced motion preferences */10@media (prefers-reduced-motion: reduce) {11 .animated-element {12 animation: none;13 transition: all 0.01s;14 }15}16 17/* Snappy for short durations */18.quick-transition {19 transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);20}21 22/* Smoother for longer animations */23.slow-transition {24 transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);25}

Common Use Cases and Examples

Different easing functions suit different animation purposes. Understanding these patterns helps you choose the right easing for each situation without trial and error.

Modal and Dialog Animations

Modals benefit from easing that creates a sense of focus and attention. A quick ease-out for the appearance (150-200ms) combined with a slightly slower ease-in for the disappearance (200-300ms) creates asymmetry that draws attention to the modal when it appears according to MDN Web Docs.

List Item Animations

Items being added to or removed from lists should feel purposeful. Adding items with a subtle bounce (cubic-bezier(0.175, 0.885, 0.32, 1.275)) creates a pleasant entrance, while removing items with a quick ease-in feels decisive according to CSS-Tricks.

Loading States

Loading indicators work best with linear or very subtle easing to maintain a consistent visual rhythm. Any dramatic easing on a spinning or pulsing loader feels irregular and can actually make the wait feel longer according to W3Schools.

Page Transitions

Page transitions often benefit from more elaborate easing to create a sense of traveling between views. A custom easing like cubic-bezier(0.4, 0, 0.2, 1) creates a material-design-inspired motion that feels intentional and polished.

Choosing the Right Easing Function

Selecting the appropriate easing function depends on several factors: the type of element being animated, its purpose in the interface, and the emotional response you want to evoke.

For user interface microinteractions like button hovers and focus states, stick with the built-in keywords--ease, ease-out, or ease-in-out. These are familiar to users and feel natural without drawing excessive attention to themselves.

For entrance and exit animations where you want to create emphasis, custom cubic-bezier functions provide the flexibility to create distinctive motion that reinforces your brand's personality. A subtle bounce on a notification badge or a smooth slide for a sidebar menu adds polish that users consciously or unconsciously appreciate.

For functional animations that indicate progress, loading, or continuous motion, linear easing ensures predictable, consistent motion that doesn't distract from the information being conveyed.

Remember that less is often more with easing functions. The goal is to create interfaces that feel natural and responsive, not to showcase every easing technique you've learned. Choose the simplest easing that accomplishes your goal, and save dramatic custom easings for moments that deserve special attention.

When building modern web applications, these animation patterns help create interfaces that feel polished and professional while providing clear user feedback throughout the experience. Combined with proper CSS conditional rules, you can create sophisticated responsive animations that adapt to different user preferences and device capabilities.

Frequently Asked Questions

Ready to Elevate Your Web Animations?

Master CSS easing functions and create polished, professional interfaces that delight users. Our team specializes in building modern web applications with smooth, performant animations.

Sources

  1. MDN Web Docs - CSS Easing Functions - Official web standards documentation for easing function types and syntax
  2. CSS-Tricks - Advanced CSS Animation Using cubic-bezier() - Advanced cubic-bezier techniques and mathematical foundations
  3. W3Schools - CSS cubic-bezier() function - Syntax reference and basic examples