DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

CSS Transitions: How to Animate Changes on a Web Page

A practical guide to CSS transitions: trigger property changes, control timing, handle reduced motion and newer entry or exit effects, and fix common problems.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a CSS transition to interpolate a property from its current value to a new value over time. Put the transition on the element’s base rule, then change the property in a state such as :hover, :focus-visible, or a class added by JavaScript. The transition controls how the change looks; it does not trigger the change itself.

A working CSS transition

This button changes color and moves slightly when hovered or keyboard-focused:

As an Amazon Associate I earn from qualifying purchases.

.button {
  background-color: #2457c5;
  transform: translateY(0);
  transition: background-color 180ms ease, transform 180ms ease;
}

.button:hover,
.button:focus-visible {
  background-color: #17449f;
  transform: translateY(-2px);
}

The base rule declares which properties transition and how. The alternate state supplies their destination values. When the state ends, the properties transition back to their base values. The values shown are an illustration, not a universally ideal duration or easing curve; choose and test motion in the context of your interface.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What the transition shorthand controls

The common shorthand form is transition: property duration timing-function delay. For example, transition: opacity 200ms ease-in 50ms transitions opacity over 200 milliseconds, using an ease-in curve, after a 50-millisecond delay.

#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
Control What it sets Example
transition-property The property or properties whose changing values should transition. Explicit names make the intended animated set clear. opacity or opacity, transform
transition-duration How long the interpolation takes. Its initial value is 0s, so a nonzero duration is needed for visible motion. 200ms
transition-timing-function How the intermediate values progress during the duration. ease, linear, or a custom easing function
transition-delay How long to wait after the value changes before beginning the transition. 50ms
transition-behavior Whether discrete properties may participate in transitions. allow-discrete

The shorthand can include all five controls. When using a shorthand property such as background, animatable longhand sub-properties may be included; naming a specific longhand such as background-color can make the intended effect easier to understand. See MDN’s transition reference and guides to using CSS transitions for syntax and examples.

Choose properties deliberately

transition-property can name one property or a comma-separated list. all applies transitions to changing properties broadly, but it can animate changes you did not intend. Listing the properties makes the scope clearer:

transition: color 180ms ease, transform 180ms ease;

Only the listed properties are transitioned. A transition also requires an actual change in value between states.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Match lists and timing

For comma-separated transition entries, duration, timing-function, and delay values form lists. If the lists have different lengths, values repeat or truncate to match the property list. Keep entries aligned when distinct properties need distinct timing; this is easier to maintain than relying on list matching rules. MDN documents the behavior for property selection, duration, timing functions, and delays.

Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Trigger the state change

A pseudo-class is one way to change a value, but transitions also work when JavaScript changes a class. Keep the transition in the base CSS rule and let the class define the new state:

.panel {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 200ms ease, transform 200ms ease;
}

.panel.is-open {
  opacity: 1;
  transform: translateY(0);
}

Adding or removing is-open changes the computed values; CSS handles interpolation. If no rule changes a transitioned property, there is nothing to animate.

Entry, exit, and discrete properties

Transitions most straightforwardly interpolate between values when an element already has a starting value. For a newly inserted element with no originating style, @starting-style can define a starting appearance. Discrete properties do not interpolate through intermediate values in the same way; transition-behavior: allow-discrete allows discrete transitions where supported. These newer capabilities can help with entry and exit effects, but check compatibility for the browsers your audience uses.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.notice {
  opacity: 1;
  transition: opacity 200ms ease, display 200ms allow-discrete;
}

.notice.is-hidden {
  opacity: 0;
  display: none;
}

This example illustrates the newer behavior rather than a fallback for older browsers. MDN explains transition behavior and the CSS transitions module, including @starting-style. Core transition properties are widely available and generally established since September 2015; MDN marks transition-behavior Baseline 2024, so older browsers may not support it. Consult the compatibility tables when targeting a particular browser or version.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Respect reduced-motion preferences

Motion can help explain state changes, but some motion can be problematic for people with cognitive concerns and may trigger vestibular disorders, epilepsy, or migraine. Offer a reduced-motion experience when a visitor has requested one. For a simple button effect, turn off the transition in that preference context:

@media (prefers-reduced-motion: reduce) {
  .button {
    transition: none;
  }
}

This is one implementation pattern, not a complete accessibility solution for every animation. For motion that continues or is essential to an interaction, consider whether users also need a way to pause or disable it. MDN discusses timing and accessibility in its timing-function reference.

Troubleshoot a transition that appears instant or does not run

  • It changes instantly: check that a nonzero duration is set. The initial duration is 0s.
  • Nothing changes visually: confirm the property’s computed value actually changes between states and that it is included in transition-property.
  • The destination value never appears: check whether another selector or declaration overrides the alternate-state rule.
  • Only some properties animate: verify that each changed property is listed and that comma-separated timing lists align with the properties as intended.
  • An entry or exit effect fails in an older browser: check support for @starting-style or transition-behavior; these features are newer than the core transition controls.

Or skip the browser setup

If you need a rendered screenshot to inspect how a transition looks, ScreenshotNeo is a website screenshot API and MCP server. A one-request capture can return an image or PDF; it does not replace writing or triggering the CSS transition.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for request options. It removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for the free plan.

Frequently Asked Questions

Does a CSS transition create an interaction or state change by itself?

No. A pseudo-class, class change, or other change must supply the new property value; the transition interpolates between values.

Are CSS transitions and CSS animations the same thing?

No. A transition responds to a change between property values; CSS animations use keyframes to define animated stages.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.