Sub topic 4
Easing: how a transition feels
Easing is the curve that controls how fast a transition moves at each moment. The duration sets how long the change takes. The easing sets how that time is spent. This chapter assumes you know the transition-* and duration-* utilities from the earlier chapters and can read a basic hover: variant.
The four built-in easing utilities
Tailwind's ease-* utilities set the transition-timing-function property.
| Class | Curve | Feel |
|---|---|---|
| `ease-linear` | `linear` | Constant speed. Looks mechanical. |
| `ease-in` | `cubic-bezier(0.4, 0, 1, 1)` | Starts slow, ends fast. |
| `ease-out` | `cubic-bezier(0, 0, 0.2, 1)` | Starts fast, ends slow. |
| `ease-in-out` | `cubic-bezier(0.4, 0, 0.2, 1)` | Slow at both ends. |
The transition, transition-colors and similar utilities already apply the ease-in-out curve. If you never write an ease-* class, you still get that curve.
Here is the button from earlier in the tutorial.
<button class="rounded bg-indigo-600 px-4 py-2 text-white transition-colors duration-200 ease-out hover:bg-indigo-700">
Save
</button>The ease-out class makes the color shift quickly at first and settle gently. The user sees a response right away.
Choosing a curve
Pick the curve by asking whether the element is reacting to the user or moving by itself.
ease-outsuits things that respond to input, such as hover effects, dropdowns and elements entering the screen. The movement starts immediately, so the interface feels responsive.ease-insuits elements leaving the screen. They gather speed and disappear. Avoid it for hover feedback, because the slow start feels like lag.ease-in-outsuits elements that move from one place to another on screen, such as a sliding panel.ease-linearsuits constant motion, such as a progress bar or a color cycle. Do not use it for UI feedback.
Easing is set on the destination state
A transition uses the timing function of the state it is moving toward. This lets you use different curves for each direction.
<div class="rounded-lg bg-white p-6 shadow transition duration-300 ease-in hover:-translate-y-1 hover:shadow-lg hover:duration-150 hover:ease-out">
Card content
</div>When the pointer enters, the hover state applies, so the card lifts over 150 ms with ease-out. When the pointer leaves, the base state applies, so the card returns over 300 ms with ease-in. A quick response and a slower return is a common pattern.
Custom curves
For a curve that the four utilities do not cover, you have three options.
An arbitrary value works for one-off cases. Write the curve without spaces, because spaces would split the class name.
<div class="transition-transform duration-500 ease-[cubic-bezier(0.34,1.56,0.64,1)] hover:scale-110">
Overshoots slightly
</div>In Tailwind v4, you can name a curve in the theme. An --ease-* variable creates a matching utility.
@import "tailwindcss";
@theme {
--ease-snappy: cubic-bezier(0.2, 0, 0, 1);
}This produces ease-snappy. In v3, you add the curve under transitionTimingFunction in the config file.
// tailwind.config.js (Tailwind v3)
module.exports = {
theme: {
extend: {
transitionTimingFunction: {
snappy: 'cubic-bezier(0.2, 0, 0, 1)',
},
},
},
};Both versions give you ease-snappy.
Common errors
- No transition utility.
ease-outdoes nothing without atransitionutility. The easing needs a transition to act on. - Spaces in arbitrary values.
ease-[cubic-bezier(0.3, 0, 0, 1)]is not parsed as one class. Remove the spaces. - Easing on animations. The
animate-*utilities carry their own timing inside theanimationshorthand, soease-*does not change them. Change the curve in the keyframe definition instead. - Overshoot curves on large moves. A curve whose y-values go above 1 makes the element overshoot. It looks lively on a small scale change and awkward on a full-screen slide.
Exercise
A card has the classes transition duration-300 ease-in hover:ease-out hover:duration-100. Describe how the card animates when the pointer enters and when it leaves.
Show answer
On entering, the hover state is the destination, so the transition runs for 100 ms with ease-out (fast start, gentle finish). On leaving, the base state is the destination, so it runs for 300 ms with ease-in (slow start, fast finish).
Exercise
You add ease-snappy to an element, but nothing animates when you hover it. The theme defines the curve correctly. What is the most likely cause?
Show answer
The element has no transition utility, such as transition or transition-colors. An easing curve only changes how a transition moves, so without a transition there is nothing to ease.