EthicsComputerCourses
Join training +91 90532 10052

Transition Timing Functions

CSS · Lesson 97 of 240 Intermediate 11 min read Updated

By the end of this lesson you will be able to read a cubic-bezier() curve, build a typewriter with steps(), make a springy effect with linear(), and pick the right easing for things that enter and leave.

CSS Transitions introduced the keywords in one short list. Here you will see what each one really does, and learn the functions behind them.

What a timing function does

A transition has a start value, an end value and a duration. The timing function (also called easing) decides how much of the change has happened at each moment.

Think of an auto-rickshaw leaving a signal in Pune. It does not jump to 40 km/h. It speeds up, cruises, then slows before the next stop. Easing is that feel.

Technically, a timing function is a small graph. The horizontal axis is time, from 0 to 1. The vertical axis is progress, from 0 (start value) to 1 (end value). A steep part of the curve means fast movement; a flat part means slow movement.

The keywords

KeywordSame asFeel
linearcubic-bezier(0, 0, 1, 1)Constant speed, mechanical
ease (default)cubic-bezier(0.25, 0.1, 0.25, 1)Quick start, long gentle stop
ease-incubic-bezier(0.42, 0, 1, 1)Slow start, fast end
ease-outcubic-bezier(0, 0, 0.58, 1)Fast start, slow end
ease-in-outcubic-bezier(0.42, 0, 0.58, 1)Slow at both ends

Each keyword is a shortcut for a cubic-bezier() curve, so once you can read one, you understand them all.

Step 1 is to watch them side by side. Each dot below travels the same distance in the same 1.5 seconds. Only the timing function differs.

HTMLOpen in editor
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Easing race</title>
  <style>
    body { font-family: system-ui, sans-serif; margin: 20px; }
    .lane {
      width: 280px;
      margin: 6px 0;
      padding: 4px;
      border-radius: 20px;
      background: #f1f5f9;
    }
    .lane span { font-size: 0.75rem; color: #475569; }
    .dot {
      width: 24px;
      height: 24px;
      border-radius: 50%;
      background: #ea580c;
      transition: translate 1.5s var(--easing);
    }
    .track.go .dot { translate: 248px 0; }
  </style>
</head>
<body>
  <button type="button" id="go">Start the race</button>
  <div class="track">
    <div class="lane"><span>linear</span><div class="dot" style="--easing: linear"></div></div>
    <div class="lane"><span>ease</span><div class="dot" style="--easing: ease"></div></div>
    <div class="lane"><span>ease-in</span><div class="dot" style="--easing: ease-in"></div></div>
    <div class="lane"><span>ease-out</span><div class="dot" style="--easing: ease-out"></div></div>
    <div class="lane"><span>ease-in-out</span><div class="dot" style="--easing: ease-in-out"></div></div>
    <div class="lane"><span>cubic-bezier(0.3, 1.5, 0.6, 1)</span><div class="dot" style="--easing: cubic-bezier(0.3, 1.5, 0.6, 1)"></div></div>
    <div class="lane"><span>steps(5)</span><div class="dot" style="--easing: steps(5)"></div></div>
  </div>
  <script>
    document.querySelector('#go').addEventListener('click', () => {
      document.querySelector('.track').classList.toggle('go');
    });
  </script>
</body>
</html>

What you should see: all dots arrive together, but ease-in lags early while ease-out rushes ahead and then slows. The cubic-bezier dot overshoots and comes back. The steps(5) dot hops in five jumps.

cubic-bezier(): reading the control points

A cubic Bezier curve always starts at point (0, 0) and ends at point (1, 1). You supply two control points in between: cubic-bezier(x1, y1, x2, y2). The curve does not pass through them. Instead, each point pulls the curve towards itself, like a magnet pulling a loose string.

  • P1 (x1, y1) shapes the start. A high, early P1 makes the start steep, so the motion begins fast.
  • P2 (x2, y2) shapes the end. A P2 near the top right line keeps the end flat, so the motion settles gently.
  • The x values are time, so they must stay between 0 and 1. A value outside that range makes the whole declaration invalid.
  • The y values are progress, and they may go below 0 or above 1. That makes the motion go backwards first (anticipation) or past the target (overshoot).

Step 2 is to drag the points yourself. The playground draws the curve and runs a dot with it.

HTMLOpen in editor
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>cubic-bezier playground</title>
  <style>
    body { font-family: system-ui, sans-serif; margin: 20px; }
    svg { width: 240px; height: 300px; background: #f8fafc; border: 1px solid #cbd5e1; }
    label { display: block; font-size: 0.85rem; }
    code { display: block; margin: 8px 0; font-size: 1rem; }
    .track { width: 280px; padding: 4px; background: #f1f5f9; border-radius: 20px; }
    .dot {
      width: 24px; height: 24px; border-radius: 50%; background: #2563eb;
      transition: translate 1.2s var(--curve);
    }
    .track.go .dot { translate: 248px 0; }
  </style>
</head>
<body>
  <svg viewBox="0 0 240 300" aria-label="Easing curve">
    <line x1="20" y1="250" x2="220" y2="50" stroke="#cbd5e1" stroke-dasharray="4"/>
    <line id="h1" stroke="#16a34a"/>
    <line id="h2" stroke="#db2777"/>
    <path id="curve" fill="none" stroke="#0f172a" stroke-width="3"/>
    <circle id="p1" r="6" fill="#16a34a"/>
    <circle id="p2" r="6" fill="#db2777"/>
  </svg>
  <label>x1 <input type="range" id="x1" min="0" max="1" step="0.01" value="0"></label>
  <label>y1 <input type="range" id="y1" min="-0.5" max="1.5" step="0.01" value="0"></label>
  <label>x2 <input type="range" id="x2" min="0" max="1" step="0.01" value="0.58"></label>
  <label>y2 <input type="range" id="y2" min="-0.5" max="1.5" step="0.01" value="1"></label>
  <code id="out"></code>
  <button type="button" id="run">Run</button>
  <div class="track"><div class="dot"></div></div>
  <script>
    const v = id => Number(document.getElementById(id).value);
    const px = x => 20 + 200 * x;   // time 0..1 to the right
    const py = y => 250 - 200 * y;  // progress 0..1 upwards
    function draw() {
      const [x1, y1, x2, y2] = [v('x1'), v('y1'), v('x2'), v('y2')];
      const set = (id, attrs) => {
        for (const [k, val] of Object.entries(attrs)) document.getElementById(id).setAttribute(k, val);
      };
      set('p1', { cx: px(x1), cy: py(y1) });
      set('p2', { cx: px(x2), cy: py(y2) });
      set('h1', { x1: px(0), y1: py(0), x2: px(x1), y2: py(y1) });
      set('h2', { x1: px(1), y1: py(1), x2: px(x2), y2: py(y2) });
      set('curve', { d: `M${px(0)} ${py(0)} C${px(x1)} ${py(y1)} ${px(x2)} ${py(y2)} ${px(1)} ${py(1)}` });
      const text = `cubic-bezier(${x1}, ${y1}, ${x2}, ${y2})`;
      document.getElementById('out').textContent = text;
      document.body.style.setProperty('--curve', text);
    }
    document.querySelectorAll('input').forEach(i => i.addEventListener('input', draw));
    document.getElementById('run').addEventListener('click', () => {
      document.querySelector('.track').classList.toggle('go');
    });
    draw();
  </script>
</body>
</html>

It starts as ease-out. Try these and run each one:

  1. Set y1 to 1.4. The curve rises above the top line, so the dot overshoots and settles back.
  2. Set y1 to -0.4 and y2 to 1. The dot first moves slightly backwards, like a bowler stepping back before the run-up.
  3. Set all four to 0, 0, 1, 1. You get linear.

One limit to remember: a property that cannot go past its range, such as opacity, simply stays at the limit during an overshoot. Use overshoot on movement and size, not on fades.

steps(): motion in jumps

steps(n, <jump-term>) divides the time into equal slices and holds the value still within each slice. Nothing moves smoothly. This suits flip-book effects, clocks that tick and text that types one character at a time.

The jump term decides where the jumps happen:

Jump termJumpsWhat you see
jump-end (default, also end)nThe start value shows first; the end value appears only at the very end
jump-start (also start)nJumps at once, so the start value never shows
jump-nonen - 1Both the start and end values get a full slice of time
jump-bothn + 1Neither the start nor the end value is held

step-start is short for steps(1, jump-start) and step-end is short for steps(1, jump-end). jump-none needs at least 2 steps.

Step 3 builds a typewriter and a set of number reels. Each reel slides a column of digits 0 to 9 upwards through a small window, and the reels differ only in their jump term.

HTMLOpen in editor
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>steps() demo</title>
  <style>
    body { font-family: system-ui, sans-serif; margin: 20px; }
    .typed {
      font: 1.25rem ui-monospace, Consolas, monospace;
      width: 0;
      overflow: hidden;
      white-space: nowrap;
      border-right: 2px solid #0f172a;
      transition: width 2.4s steps(24, jump-end);
    }
    .go .typed { width: 24ch; }
    .reels { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 16px; }
    .reel { text-align: center; font-size: 0.75rem; }
    .window {
      width: 40px; height: 40px; margin: 4px auto;
      overflow: hidden; border: 2px solid #0f172a; border-radius: 6px;
    }
    .digits {
      width: 1ch;
      margin-inline: auto;
      font: bold 1.5rem/40px ui-monospace, Consolas, monospace;
      transition: translate 4.5s var(--steps);
    }
    .go .digits { translate: 0 -360px; }
  </style>
</head>
<body>
  <button type="button" id="go">Play</button>
  <div id="stage">
    <p class="typed">Chai ready at platform 3</p>
    <div class="reels">
      <div class="reel"><div class="window"><div class="digits" style="--steps: steps(9, jump-end)">0 1 2 3 4 5 6 7 8 9</div></div>9, jump-end</div>
      <div class="reel"><div class="window"><div class="digits" style="--steps: steps(9, jump-start)">0 1 2 3 4 5 6 7 8 9</div></div>9, jump-start</div>
      <div class="reel"><div class="window"><div class="digits" style="--steps: steps(10, jump-none)">0 1 2 3 4 5 6 7 8 9</div></div>10, jump-none</div>
      <div class="reel"><div class="window"><div class="digits" style="--steps: steps(8, jump-both)">0 1 2 3 4 5 6 7 8 9</div></div>8, jump-both</div>
    </div>
  </div>
  <script>
    document.querySelector('#go').addEventListener('click', () => {
      document.querySelector('#stage').classList.toggle('go');
    });
  </script>
</body>
</html>

The strip is one character wide (1ch), so each space wraps the next digit onto a new 40px line. Watch which digits get screen time:

  • jump-end shows 0 to 8, and 9 only arrives as the transition finishes.
  • jump-start skips 0 at once and holds 9 for the last slice.
  • jump-none holds every digit from 0 to 9 for an equal time. This is usually what you want for a reel or a sprite sheet.
  • jump-both shows only 1 to 8 while it runs.

The typewriter uses 24 steps for 24 characters and a monospace font, where 1ch is the width of one character. Each step reveals exactly one letter. In a real project you would usually type with a keyframe animation, covered in Keyframes; the timing function works the same way there.

linear(): springs and bounces

cubic-bezier() can overshoot only once. A real spring wobbles a few times before it settles. The linear() function draws an easing from a list of points joined by straight lines, so with enough points it can trace any shape.

CSS
.toast {
  transition: translate 600ms
    linear(0, 0.39, 0.92, 1.15, 1.13, 1.04, 0.98, 0.97, 0.99, 1 75%, 1);
}

Each number is a progress value. Points without a percentage are spread evenly in time, so here the first ten points share the first 75% of the time, and the last 25% holds still at 1. You can add one percentage to place a point (1 75%) or two to hold a value over a range. linear(0, 1) is the same as the linear keyword.

Developers usually generate these points with an easing tool rather than by hand. The points above sample a damped spring every twelfth of the duration.

Easing for enter and exit

Use these as starting points:

  • Entering (a menu opens, a toast appears): ease-out. It arrives quickly and settles, so the user sees the content early.
  • Leaving (a dialog closes, an item is removed): ease-in, and slightly shorter. It gathers speed and gets out of the way.
  • Moving within the screen (a tab indicator slides): ease-in-out.
  • Colour, opacity, spinners and progress bars: linear or ease is fine.

A transition uses the timing function from the style the element is changing to. So you can give each direction its own easing by putting a different transition on each state.

HTMLOpen in editor
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Enter and exit easing</title>
  <style>
    body { font-family: system-ui, sans-serif; margin: 20px; overflow-x: hidden; }
    .panel {
      position: fixed; inset-block: 0; inset-inline-end: 0;
      width: 220px; padding: 16px;
      background: #1e3a8a; color: white;
      translate: 100% 0;
      /* closing: speeds up and leaves quickly */
      transition: translate 180ms ease-in;
    }
    .panel.open {
      translate: 0 0;
      /* opening: arrives fast, settles gently */
      transition: translate 280ms ease-out;
    }
  </style>
</head>
<body>
  <button type="button" id="toggle">Show today's timetable</button>
  <aside class="panel">
    <h2>Class 10B</h2>
    <p>Maths, Science, Hindi, Lunch, English</p>
  </aside>
  <script>
    document.querySelector('#toggle').addEventListener('click', () => {
      document.querySelector('.panel').classList.toggle('open');
    });
  </script>
</body>
</html>

Open and close the panel a few times. Then swap the two timing functions: the panel now feels lazy on the way in and sticky on the way out.

Tuning easing in DevTools

You do not have to guess control points.

  1. Open DevTools (F12) and select an element that has a transition.
  2. In the Styles pane, find the timing function value. A small curve icon appears next to it.
  3. Click the icon. An editor opens with presets and two draggable handles, and a preview runs the curve.
  4. Drag a handle. The cubic-bezier() value in the rule updates live, so you can copy it into your stylesheet.

In Chrome, the Animations panel (Ctrl+Shift+P, then type "animations") records each transition and can replay it at 25% or 10% speed.

Common mistakes

  • Using linear for movement. Real objects speed up and slow down, so linear movement looks robotic.
  • An x value outside 0 to 1 in cubic-bezier(). The declaration is invalid and silently ignored.
  • Overshoot on opacity. It cannot go above 1, so the bounce is invisible. Use it on translate or scale.
  • The wrong step count. A typewriter needs one step per character, and a reel or sprite sheet usually needs jump-none so the first and last frames both show.
  • Springs everywhere. Save bouncy easing for moments that deserve attention, and calm it down for people who ask for less motion, as covered in prefers-reduced-motion.

Interview questions

1. What is the default timing function for a CSS transition, and what does it look like?

The default is ease, which equals cubic-bezier(0.25, 0.1, 0.25, 1). It starts fairly fast and spends a long time slowing down. For elements that appear, ease-out is often a better fit.

2. Explain the four numbers in cubic-bezier().

They are the coordinates of two control points, P1 (x1, y1) and P2 (x2, y2), on a graph of time against progress. The curve starts at (0, 0), ends at (1, 1) and is pulled towards each control point. The x values must be between 0 and 1, while y values outside that range create anticipation or overshoot.

3. What is the difference between steps(4, jump-start) and steps(4, jump-end)?

Both make four jumps. With jump-start the first jump happens immediately, so the starting value is never held. With jump-end the starting value shows for the first quarter and the final value only appears at the end.

4. What does linear() add that cubic-bezier() cannot do?

linear() joins any number of points with straight lines, so it can describe curves with several bounces, such as a spring or a ball dropping. A cubic-bezier() has only two control points, so it can overshoot at most once. linear() has been Baseline since 2023.

5. Which easing would you use for a dropdown opening and closing, and why?

ease-out for opening, because the menu appears quickly and then settles, so the user can read it sooner. ease-in with a shorter duration for closing, so it leaves quickly. You can set different transitions on the open and closed states because the transition is taken from the state being entered.

Key points

  • A timing function maps time to progress; steep parts are fast and flat parts are slow.
  • ease, ease-in, ease-out, ease-in-out and linear are all cubic-bezier() curves.
  • In cubic-bezier(x1, y1, x2, y2), x values stay between 0 and 1; y values outside it give overshoot or anticipation.
  • steps() moves in jumps; the jump term decides whether the first and last values are held, and jump-none suits reels and sprites.
  • linear() builds springy or bouncy easing from a list of points and is Baseline 2023.
  • Use ease-out for entering, a shorter ease-in for leaving, and tune curves in the DevTools easing editor.

Exercise

Build a "Download ticket" button for a railway booking page. Below it, add a progress bar (a track with a coloured fill). When the button is clicked, the fill should grow from 0 to full width in exactly 10 visible chunks over 2 seconds, with the first chunk visible at once and the last chunk held before the end. Then add a small "Done" badge that springs in with scale and a linear() easing, with an ease-out fallback for older browsers.

Show solution
HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Ticket download</title>
  <style>
    body { font-family: system-ui, sans-serif; margin: 20px; }
    .bar { width: 260px; height: 14px; margin: 12px 0; background: #e2e8f0; border-radius: 7px; overflow: hidden; }
    .fill {
      height: 100%; background: #16a34a;
      scale: 0 1; transform-origin: left;
      transition: scale 2s steps(10, jump-start);
    }
    .badge {
      display: inline-block; padding: 4px 10px; border-radius: 12px;
      background: #16a34a; color: white;
      scale: 0;
      transition-property: scale;
      transition-duration: 500ms;
      transition-delay: 2s;
      transition-timing-function: ease-out;
      transition-timing-function: linear(0, 0.39, 0.92, 1.15, 1.13, 1.04, 0.98, 0.97, 0.99, 1 75%, 1);
    }
    .done .fill, .done .badge { scale: 1; }
  </style>
</head>
<body>
  <div id="box">
    <button type="button" id="dl">Download ticket</button>
    <div class="bar"><div class="fill"></div></div>
    <span class="badge">Done</span>
  </div>
  <script>
    document.querySelector('#dl').addEventListener('click', () => {
      document.querySelector('#box').classList.add('done');
    });
  </script>
</body>
</html>

steps(10, jump-start) shows the first chunk immediately and holds the full bar for the last tenth of the time. The fill grows with scale from its left edge, which is cheaper than animating width. The badge waits 2 seconds, then springs in; browsers without linear() drop that line and keep ease-out.

Quick Quiz

1. Which of these declarations is invalid?

2. A transition uses steps(9, jump-end) from digit 0 to digit 9. Which digit is never held while it runs?

3. Which easing is usually best for a menu that is opening?

4. A panel has transition: translate 180ms ease-in and .panel.open has transition: translate 280ms ease-out. Which one runs when the class open is added?

Learn CSS with a mentor

Free lessons get you started. Our Full Stack Web Development training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call