Sub topic 4
Easing: how a transition feels
Duration sets how long a transition takes. Easing sets how the change is spread across that time. Two buttons can both finish in 200 ms and still feel different, because one starts fast and settles gently while the other moves at a constant speed. This chapter covers Tailwind's easing utilities, how the browser picks an easing for each direction of a transition, and how to add your own curves.
This chapter assumes you know how state variants trigger a transition (hover:, focus:), and that you have used transition-* and duration-* to set what animates and for how long. It also assumes you can read a small Tailwind config or CSS file. Examples work in Tailwind v3 and v4 unless a note says otherwise.
What an easing function does
A transition moves a property from a start value to an end value. The easing function (CSS calls it a timing function) maps elapsed time to progress. At 50% of the time, a linear easing has completed 50% of the change. An ease-out curve has completed more than that, and an ease-in curve has completed less.
CSS describes most curves as a cubic-bezier(x1, y1, x2, y2). The x values must stay between 0 and 1, because time cannot run backwards. The y values describe progress and may go outside 0 to 1, which produces overshoot.
The four built-in utilities
Tailwind exposes the common curves as ease-* utilities. They set the transition-timing-function property.
| Utility | CSS value | Feel |
|---|---|---|
| `ease-linear` | `linear` | Constant speed, mechanical |
| `ease-in` | `cubic-bezier(0.4, 0, 1, 1)` | Starts slowly, ends fast |
| `ease-out` | `cubic-bezier(0, 0, 0.2, 1)` | Starts fast, ends slowly |
| `ease-in-out` | `cubic-bezier(0.4, 0, 0.2, 1)` | Slow at both ends |
Tailwind v4 also adds ease-initial, which resets the property to the browser default (ease). Without any ease-* class, transition, transition-colors and the other transition utilities already set a timing function. In v3 and v4 that default is cubic-bezier(0.4, 0, 0.2, 1), the same curve as ease-in-out. Adding ease-in-out therefore changes nothing unless you are overriding another class.
A typical use puts the easing next to the duration:
<button class="rounded bg-indigo-600 px-4 py-2 text-white transition-colors duration-200 ease-out hover:bg-indigo-700">
Save
</button>Comparing the curves side by side
The quickest way to learn the curves is to watch them run together. Hovering the container sends four squares across the same distance in the same 700 ms. Only the easing differs.
<div class="group w-80 space-y-2 rounded-lg bg-slate-100 p-4">
<div class="size-8 rounded bg-slate-500 transition-transform duration-700 ease-linear group-hover:translate-x-64"></div>
<div class="size-8 rounded bg-indigo-400 transition-transform duration-700 ease-in group-hover:translate-x-64"></div>
<div class="size-8 rounded bg-indigo-600 transition-transform duration-700 ease-out group-hover:translate-x-64"></div>
<div class="size-8 rounded bg-indigo-800 transition-transform duration-700 ease-in-out group-hover:translate-x-64"></div>
</div>The container is 20 rem wide with 1 rem of padding on each side. Each square is 2 rem wide, so translate-x-64 (16 rem) moves it exactly to the right edge. The ease-in square lags and then rushes at the end. The ease-out square leaps forward and then drifts into place. All four arrive together, because easing changes the distribution of progress and not the total time.
Which easing applies in which direction
A transition plays on entry and on exit. When the pointer leaves, the element returns to its base style, and that return is also a transition. The browser takes the timing function from the style the element is moving toward. This has two consequences:
- Utilities written without a variant, such as
ease-out, apply when the element returns to its base state. - Utilities written with a variant, such as
hover:ease-in, apply only while the element is moving toward the hovered state.
You can use this to give each direction its own feel:
<div class="size-24 rounded-lg bg-indigo-600 transition-transform duration-300 ease-in hover:ease-out hover:scale-110"></div>When the pointer enters, the element is heading toward the hover style, so hover:ease-out governs and the growth starts fast. When the pointer leaves, the base ease-in governs and the shrink starts slowly. The same rule applies to duration-* and delay-*, so you can make a hover-in quick and a hover-out slower.
Choosing an easing for the job
Match the curve to what the user is seeing.
- Use ease-out for things that arrive in response to the user, such as menus opening, tooltips appearing, and hover feedback. The fast start gives immediate feedback, and the slow end keeps the motion from feeling abrupt.
- Use ease-in for things that leave the screen. A dismissed toast can start slowly and then accelerate out. Ease-in on an arriving element feels sluggish, because nothing visible happens at the start.
- Use ease-in-out for movement within the page, such as a sliding panel or an element changing position. Both ends are soft, like a vehicle accelerating and braking.
- Use ease-linear for constant-rate motion, such as progress bars and rotating spinners. A linear curve on a hover effect looks stiff.
Duration and easing work together. A short duration of 150 to 200 ms hides most differences between curves, so the choice matters more at 300 ms and above.
Custom curves with arbitrary values
When the four presets are not enough, put a curve in square brackets. This works in v3 and v4 and needs no configuration:
<div class="size-24 rounded-lg bg-indigo-600 transition-transform duration-500 ease-[cubic-bezier(0.34,1.56,0.64,1)] hover:scale-125"></div>The second y value, 1.56, is above 1, so progress passes the end value and settles back. The square overshoots its 125% scale and returns, which gives a springy feel. Write the curve without spaces, because spaces would split the class name. Overshoot is visible on transforms. It has no useful effect on opacity or colors, because the browser clamps those values to their valid range.
In v4 you can also point at a CSS variable with ease-(--my-curve). In v3 the equivalent is ease-[var(--my-curve)].
Adding a named easing to the theme
If you reuse a curve, name it once. In v4, define an --ease-* variable in @theme:
@import "tailwindcss";
@theme {
--ease-snappy: cubic-bezier(0.2, 0, 0, 1);
--ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}Tailwind generates ease-snappy and ease-spring from these variables. In v3, add the curves under transitionTimingFunction in the config file:
// tailwind.config.js (Tailwind v3)
module.exports = {
theme: {
extend: {
transitionTimingFunction: {
snappy: 'cubic-bezier(0.2, 0, 0, 1)',
spring: 'cubic-bezier(0.34, 1.56, 0.64, 1)',
},
},
},
};Both versions give you the same markup:
<div class="size-24 rounded-lg bg-indigo-600 transition-transform duration-500 ease-spring hover:scale-125"></div>Using extend keeps the four built-in curves. Putting the same keys directly under theme in v3 would replace them.
Easing does not affect `animate-*` utilities
The ease-* utilities set transition-timing-function. Keyframe animations use a different property, animation-timing-function, and Tailwind has no utility class for it. An ease-out class on an element with animate-pulse has no effect.
For a custom animation, write the curve inside the animation value. The --animate-* variable in v4 is a shorthand like any other CSS animation value:
@import "tailwindcss";
@theme {
--animate-pop: pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
@keyframes pop {
0% { transform: scale(0.8); }
100% { transform: scale(1); }
}
}An easing in an animation applies to each interval between keyframes, not to the whole animation. A three-step animation with ease-in-out eases in and out at every step. If you want one smooth motion across the whole animation, use only two keyframes, or set animation-timing-function inside individual keyframe blocks to control each step. The built-in animate-spin uses linear for this reason: a rotation that eased at each turn would visibly stutter.
Common mistakes
- Expecting visible differences at 100 ms. Over such a short time the curves are nearly indistinguishable. Test at a longer duration while you tune, then shorten it.
- Using ease-in for entrances. The element appears to hesitate. Switch to ease-out.
- Adding
ease-*without a transition utility. The easing has nothing to act on. Pair it withtransition,transition-colors,transition-transformor another transition class. - Overshoot on non-transform properties. A
cubic-bezierwith y above 1 on a color or opacity gives no visible bounce, and on some properties it can look like a flicker. Reserve it for transforms. - Putting the curve on the wrong state. An easing on the hover variant does not apply on the way back. Set the base easing for the return trip.
Exercise
A card has the classes transition-transform duration-300 ease-out hover:-translate-y-1 hover:ease-in. When the pointer enters the card, which easing curve controls the lift, and which controls the drop when the pointer leaves?
Show answer
The lift uses ease-in, because the browser takes the timing function from the style the element is moving toward, which on entry is the hover style. The drop uses ease-out from the base style. This is probably the reverse of what was intended: arriving feedback usually wants ease-out, so the two utilities should swap places.
Exercise
You add ease-in-out to an element with animate-bounce, expecting the bounce to feel smoother, but nothing changes. Why, and where would you change the curve instead?
Show answer
ease-in-out sets transition-timing-function, and animate-bounce is a keyframe animation that reads animation-timing-function. The two do not interact. To change the curve, define a custom animation whose value includes the timing function, for example --animate-soft-bounce: bounce 1s cubic-bezier(0.4, 0, 0.2, 1) infinite; in v4 @theme, or set it in the animation entry in v3 config.