What Are CSS Transitions?
CSS transitions allow a change between two CSS states to happen gradually instead of immediately. Without a transition, when a property changes, the browser normally moves directly from the old value to the new value. A transition tells the browser to interpolate the intermediate values over a period of time.
This is commonly used for buttons, navigation links, cards, dropdown states, form controls, menus, and other interactive components. For example, changing a button's background color on hover normally happens immediately.
button {
background: #2563eb;
}
button:hover {
background: #7c3aed;
}
Adding a transition causes the browser to animate the change between those two states.
button {
background: #2563eb;
transition: background-color 200ms ease;
}
button:hover {
background: #7c3aed;
}
CSS transitions are often called implicit transitions because the browser generates the intermediate states between a starting value and a target value.
How Does a CSS Transition Work?
A CSS transition needs a property whose value changes and transition settings that tell the browser how that change should occur.
transition-property
Determines which CSS property or properties should transition.
transition-duration
Defines how long the transition takes to complete.
transition-timing-function
Controls the speed curve used during the transition.
transition-delay
Defines how long the browser waits before starting the transition.
transition-behavior
Controls whether transitions can run for properties with discrete animation behavior, such as display in supported scenarios.
The transition shorthand combines these settings into
a compact declaration.
.box {
transition: opacity 250ms ease-in-out 100ms;
}
What Is transition-property?
The transition-property property specifies which CSS
properties should transition when their values change.
.button {
transition-property: background-color;
transition-duration: 200ms;
}
.button:hover {
background-color: #7c3aed;
}
You can transition several properties by separating them with commas.
.card {
transition-property: transform, box-shadow, opacity;
transition-duration: 200ms;
}
The special value all can be used to transition all
properties that can transition as the state changes.
.card {
transition-property: all;
}
Although all is convenient for quick prototypes,
explicitly listing the properties you actually intend to animate generally makes the
component's behavior easier to reason about.
What Is transition-duration?
The transition-duration property defines how long
the transition takes. Time values are usually written in milliseconds
(ms) or seconds (s).
.fast {
transition-duration: 100ms;
}
.normal {
transition-duration: 250ms;
}
.slow {
transition-duration: 800ms;
}
The default transition duration is 0s, so simply
changing a property does not create a visible transition unless a non-zero duration is
specified.
Multiple durations can be supplied for multiple transition properties.
.card {
transition-property: opacity, transform;
transition-duration: 200ms, 350ms;
}
The durations are matched to the transition-property list according to CSS's list-value rules. Keeping related lists clear and reasonably short makes complex transitions easier to maintain.
What Is transition-timing-function?
The transition-timing-function controls how the
intermediate values progress during the transition. It determines the acceleration curve,
not the total duration.
.linear {
transition-timing-function: linear;
}
.ease {
transition-timing-function: ease;
}
.ease-in {
transition-timing-function: ease-in;
}
.ease-out {
transition-timing-function: ease-out;
}
.ease-in-out {
transition-timing-function: ease-in-out;
}
Different timing functions communicate different motion characteristics. For many UI
interactions, ease or
ease-out can provide a natural-looking result.
You can also define custom cubic Bézier curves.
</pre>
<p>
Step-based timing functions are useful for discrete-looking movement or frame-like effects.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.loader {
transition-timing-function: steps(4, end);
}
What Is transition-delay?
The transition-delay property specifies how long the
browser waits after a property change before starting the transition.
.tooltip {
transition:
opacity 200ms ease,
transform 200ms ease;
transition-delay: 100ms;
}
A negative delay is also allowed. It causes the transition to behave as though it had already been running for part of its duration when the state change occurs.
</pre>
<p>
Negative delays are more advanced and are less common in ordinary interface interactions,
but they can be useful when synchronizing visual effects.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">How Does the transition Shorthand Work?</h2>
<p>
The <code class="text-cyan-300">transition</code> shorthand provides a concise way to
define transition settings.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.button {
transition:
background-color 200ms ease
transform 150ms ease-out;
}
A single transition description can contain a property name, duration, timing function, delay, and, when needed, a discrete transition behavior.
</pre>
<p>
When a time value appears first, it is interpreted as the duration. When two time values
are provided, the first is the duration and the second is the delay.
</p>
<p>
Multiple transitions are separated by commas.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.card {
transition:
transform 200ms ease,
opacity 250ms ease-in-out,
box-shadow 300ms ease;
}
How Do CSS Transitions Work with :hover?
Hover states are one of the most familiar uses of CSS transitions. The transition should usually be defined on the base state so that both entering and leaving the hover state receive the same transition behavior.
</pre>
<p>
If the transition is placed only inside <code class="text-cyan-300">:hover</code>,
the hover-in and hover-out behavior can become asymmetric because the base state does
not retain the transition declaration.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">How Do CSS Transitions Work with :focus-visible?</h2>
<p>
Interactive controls should not rely solely on pointer hover. Keyboard and other
non-pointer interactions need clear focus feedback as well.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.button {
outline: 2px solid transparent;
outline-offset: 3px;
transition:
background-color 180ms ease,
outline-color 180ms ease;
}
.button:hover {
background-color: #1d4ed8;
}
.button:focus-visible {
outline-color: currentColor;
}
This creates a visual transition for the focus indicator while keeping the focus state explicit and accessible.
Avoid removing focus indicators merely to achieve a cleaner visual design. Interaction feedback should remain understandable for keyboard users.
Which CSS Properties Can Be Transitioned?
CSS transitions work with properties that have an animation behavior allowing meaningful interpolation between the old and new values. Many common visual properties can transition, including colors, opacity, dimensions, spacing, and transforms.
</pre>
<p>
Not every CSS property has continuously interpolatable values. Some properties have
discrete animation behavior and normally switch between states instead of smoothly
interpolating numeric values.
</p>
<p>
This distinction is important when a developer expects a smooth animation from a property
that fundamentally changes as a discrete state.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">What Is transition-behavior?</h2>
<p>
Modern CSS introduces <code class="text-cyan-300">transition-behavior</code>, which can
allow transitions for properties with discrete animation behavior when
<code class="text-cyan-300">allow-discrete</code> is used.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.panel {
transition-property: opacity, display;
transition-duration: 250ms;
transition-behavior: allow-discrete;
}
.panel.hidden {
opacity: 0;
display: none;
}
This capability is particularly useful for modern UI patterns where an element needs to
transition its visual state while also changing a discrete property such as
display.
Because browser support and the exact behavior of discrete transitions can matter for production interfaces, test this technique against the browser support requirements of your application and provide appropriate fallbacks for environments that do not support it.
What Is @starting-style?
CSS transitions normally need an existing starting state from which a property changes.
Modern CSS also provides the @starting-style at-rule,
which can define the initial styles used when an element begins participating in the
document or otherwise lacks a normal rendered starting state.
</pre>
<p>
This opens up more natural transition patterns for dynamically inserted content and
other modern UI features. As with newer CSS capabilities, confirm browser support when
using the technique in production.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">How Do You Transition Multiple Properties?</h2>
<p>
A component often needs several properties to change together. You can explicitly list
each property in the transition shorthand.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.card {
background-color: #ffffff;
border-color: #cbd5e1;
transform: translateY(0);
box-shadow: 0 4px 12px rgb(0 0 0 / 0.06);
transition:
background-color 180ms ease,
border-color 180ms ease,
transform 180ms ease,
box-shadow 180ms ease;
}
.card:hover {
background-color: #f8fafc;
border-color: #94a3b8;
transform: translateY(-4px);
box-shadow: 0 16px 30px rgb(0 0 0 / 0.10);
}
Explicit declarations make the intent obvious and prevent unrelated properties from unexpectedly participating in the transition.
How Do Transitions Differ from CSS Animations?
| Feature | Transition | Animation |
|---|---|---|
| Primary model | Transition between states | Timeline-based keyframes |
| Typical trigger | Property value change | Animation declaration |
| Multiple stages | Normally two endpoint states | Supports multiple keyframes |
| Example | Button hover color change | Continuous loading indicator |
Use transitions when an element should move smoothly between states. Use CSS animations when you need a defined sequence, repeated cycles, multiple keyframes, or an effect that does not depend on a simple state change.
Why Does transition Not Work?
When a transition appears not to work, first check whether the property actually changes between two states and whether the property can transition in the way you expect.
</pre>
<p>
Common problems include setting a duration of zero, transitioning the wrong property,
placing the transition on only one state, overriding the transition later in the stylesheet,
or trying to smoothly interpolate a property whose value changes discretely.
</p>
<p>
DevTools are useful for checking the computed style in both states and confirming which
declarations are actually winning in the cascade.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">Should You Use transition: all?</h2>
<p>
<code class="text-cyan-300">transition: all</code> can be convenient, but it is usually
better to specify the properties that are actually intended to transition.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code>/* Convenient but broad */
.card {
transition: all 200ms ease;
}
/* More explicit */
.card {
transition:
transform 200ms ease,
box-shadow 200ms ease,
opacity 200ms ease;
}
Explicit properties communicate design intent and reduce the chance that an unrelated property change produces an unexpected animation.
This becomes increasingly valuable in large components where styles can change for reasons unrelated to the interaction currently being designed.
How Do CSS Transitions Work with Transform?
Transitions and transforms work together particularly well for interactive UI effects. A transform can define the visual movement while the transition controls the timing.
</pre>
<p>
This pattern is commonly used for cards, buttons, thumbnails, navigation items, and
interactive previews because the layout can remain stable while the element changes visually.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">How Do You Build a Smooth Button Transition?</h2>
<p>
A good button transition usually combines a small visual change with a short duration.
You can transition the background color, border color, color, and transform independently.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.button {
background-color: #2563eb;
color: white;
border: 1px solid #2563eb;
transform: translateY(0);
transition:
background-color 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.button:hover {
background-color: #1d4ed8;
border-color: #1d4ed8;
transform: translateY(-1px);
}
.button:active {
transform: translateY(0);
}
This creates a clear relationship between the button state and the visual feedback without introducing unnecessary movement.
How Should You Handle Reduced Motion?
Non-essential transitions and other motion effects should respect the user's reduced-motion
preference when appropriate. The prefers-reduced-motion
media feature can be used to reduce or remove visual movement.
Not every transition needs to be completely removed. The appropriate response depends on whether the motion communicates meaningful state or is purely decorative. The goal is to avoid unnecessary motion while preserving understandable interaction feedback.
How Do Transitions Affect Performance?
Transitions can be inexpensive when used appropriately, but the property being transitioned matters. Changes to layout-related properties can cause more rendering work than effects that can be handled efficiently during compositing.
Properties such as transform and
opacity are often good choices for motion effects because
browsers can optimize many such cases effectively. This does not mean that every transform
is automatically free or that layout properties should never transition.
For complex pages, profile actual performance rather than assuming that one property is always faster in every scenario.
Common CSS Transition Mistakes
Defining the transition only on :hover
This can make entering and leaving the state behave differently. Put the transition on the base component state in most cases.
Using an unnecessarily long duration
Very slow interactions can make normal UI controls feel unresponsive.
Transitioning everything
transition: all can animate unrelated property changes and make components difficult to predict.
Expecting discrete properties to interpolate normally
Some properties change as discrete states rather than smoothly varying values.
Ignoring keyboard and reduced-motion users
Hover-only feedback and unnecessary motion can reduce usability and accessibility.
Best Practices for CSS Transitions
Transition only intended properties
Explicit property lists make component behavior easier to understand and maintain.
Keep interaction durations reasonable
Choose durations that communicate state changes without making controls feel delayed.
Put the transition on the base state
This normally produces consistent transitions into and out of interactive states.
Choose timing functions intentionally
Use easing to control the feel of motion instead of treating every transition as linear.
Respect reduced motion
Reduce or remove non-essential transitions when users request less motion.
Use newer transition features deliberately
Features such as transition-behavior and @starting-style can solve modern UI problems, but should be tested against your application's browser support requirements.
Final Takeaway
CSS transitions provide a simple and powerful way to create smooth state changes.
The core concepts are transition-property,
transition-duration,
transition-timing-function,
and transition-delay, commonly combined with the
transition shorthand.
For modern interfaces, it is also useful to understand
transition-behavior and
@starting-style when a design needs transitions for
newer UI patterns involving dynamically appearing content or discrete properties.
The best transition is usually the one that communicates a state change clearly without slowing the interface down or distracting the user. Use explicit property lists, sensible durations, appropriate easing, accessible focus states, and reduced-motion handling to create interactions that feel intentional and reliable.