Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

transition — CSS transition shorthand

The transition property defines a transition between old and new CSS property values. It combines property selection, duration, easing, delay, and the behavior of discrete transitions.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

transition: <single-transition>#;
<single-transition> = [ none | <single-transition-property> ] || <time> || <easing-function> || <time> || <transition-behavior-value>
<single-transition-property> = all | <custom-ident>
<transition-behavior-value> = normal | allow-discrete

transition configures a transition after a value changes; it does not cause the change itself. Level 1 covers transition-property, transition-duration, transition-timing-function, and transition-delay. Level 2 adds transition-behavior.

The first time is the duration; the second is the delay. Duration cannot be negative. A negative delay starts the transition partway through only if the sum of the duration and delay is positive. If the magnitude of the negative delay equals or exceeds the duration, that sum is zero or less and no transition starts. Commas separate transition descriptions; # in the grammar denotes that list.

Omitted components reset to all, 0s, ease, 0s, and normal. all covers eligible properties, while none disables transitions. With normal, discrete values do not transition; allow-discrete permits them but does not provide smooth interpolation.

In the example, checking the box changes opacity from 1 to 0.25. A full, uninterrupted transition takes 400ms, linearly and without delay. Unchecking reverses the change. The example requires local verification.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Transition shorthand for an opacity fade</title>
  <style>
    .box {
      width: 80px;
      height: 80px;
      margin-block-start: 12px;
      background: navy;
      opacity: 1;
      transition: opacity 400ms linear 0s;
    }
    #toggle:checked ~ .box { opacity: 0.25; }
  </style>
</head>
<body>
  <input id="toggle" type="checkbox">
  <label for="toggle">Dim the square</label>
  <div class="box" aria-hidden="true"></div>
  <p>The declared duration is 400 ms. Reversing a fade while it is running can shorten the return transition.</p>
  <script>
    const toggle = document.getElementById('toggle');
    const box = document.querySelector('.box');
    const style = getComputedStyle(box);
    console.log(`Computed shorthand components: ${style.transitionProperty}, ${style.transitionDuration}, ${style.transitionTimingFunction}, ${style.transitionDelay}`);
    console.log(`Settled unchecked opacity: ${style.opacity}`);
    toggle.checked = true;
    const [fade] = box.getAnimations();
    fade.pause();
    fade.currentTime = 200;
    console.log(`Opacity 200ms into the fade from rest: ${style.opacity}`);
    fade.finish();
    console.log(`Settled checked opacity: ${style.opacity}`);
  </script>
</body>
</html>

Result

Computed shorthand components: opacity, 0.4s, linear, 0s
Settled unchecked opacity: 1
Opacity 200ms into the fade from rest: 0.625
Settled checked opacity: 0.25

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources