transition
==========

The **`transition`** CSS property is a shorthand property for `transition-property`, `transition-duration`, `transition-timing-function`, `transition-delay`, and `transition-behavior`.

Try it
------

Transitions enable you to define the transition between two states of an element. Different states may be defined using pseudo-classes like `:hover` or `:active` or dynamically set using JavaScript.

Constituent properties
----------------------

This property is a shorthand for the following CSS properties:

* `transition-behavior` 
Experimental
* `transition-delay`
* `transition-duration`
* `transition-property`
* `transition-timing-function`
Syntax
------


```css
/\* Apply to 1 property \*/
/\* property name | duration \*/
transition: margin-right 4s;

/\* property name | duration | delay \*/
transition: margin-right 4s 1s;

/\* property name | duration | easing function \*/
transition: margin-right 4s ease-in-out;

/\* property name | duration | easing function | delay \*/
transition: margin-right 4s ease-in-out 1s;

/\* property name | duration | behavior \*/
transition: display 4s allow-discrete;

/\* Apply to 2 properties \*/
transition:
  margin-right 4s,
  color 1s;

/\* Apply to all changed properties \*/
transition: all 0.5s ease-out allow-discrete;
transition: 200ms linear 50ms;

/\* Global values \*/
transition: inherit;
transition: initial;
transition: revert;
transition: revert-layer;
transition: unset;
```


The `transition` property value is specified as one of the following:

* The special value `none`, which specifies that no transitions will occur on this element. This is the default value.
* One or more single-property transitions, separated by commas.

Each single-property transition describes the transition that should be applied to a single property or all properties. It includes:

* zero or one value representing the property or properties to which the transition should apply. This can be set as:
    + A `<custom-ident>` representing a single property.
    + The special value `all`, which specifies that the transition will be applied to all properties that change as the element changes state.
    + No value, in which case a value of `all` will be inferred and the specified transition will still apply to all changing properties.
* zero or one `<easing-function>` value representing the easing function to use
* zero, one, or two `<time>` values. The first value that can be parsed as a time is assigned to the `transition-duration`, and the second value that can be parsed as a time is assigned to `transition-delay`.
* zero or one value declaring whether to start transitions for properties whose animation behavior is discrete. The value, if present, is either the keyword `allow-discrete` or the keyword `normal`.

If you specify `all` as the transition property for one single-property transition, but then specify subsequent single-property transitions with `<custom-ident>` values, those subsequent transitions will override the first one. For example:


```css
transition:
  all 200ms,
  opacity 400ms;
```


In this case, all the properties that change as the element changes state will transition with a duration of 200ms except for `opacity`, which will take 400ms to transition.

See how things are handled when lists of property values aren't the same length. In short, extra transition descriptions beyond the number of properties actually being animated are ignored.

Formal definition
-----------------

|  |  |
| --- | --- |
| Initial value | as each of the properties of the shorthand:* `transition-delay`: `0s`
* `transition-duration`: `0s`
* `transition-property`: all
* `transition-timing-function`: `ease`
* `transition-behavior`: `normal`
 |
| Applies to | all elements, `::before` and `::after` pseudo-elements |
| Inherited | no |
| Computed value | as each of the properties of the shorthand:* `transition-delay`: as specified
* `transition-duration`: as specified
* `transition-property`: as specified
* `transition-timing-function`: as specified
* `transition-behavior`: as specified
 |
| Animation type | Not animatable |

Formal syntax
-------------
```

transition =   
  <single-transition>#    
  
<single-transition> =   
  [ none | <single-transition-property> ]  ||  
  <time>                                   ||  
  <easing-function>                        ||  
  <time>                                     
  
<single-transition-property> =   
  all             |  
  <custom-ident>    
  
<easing-function> =   
  linear                          |  
  <linear-easing-function>        |  
  <cubic-bezier-easing-function>  |  
  <step-easing-function>            
  
<linear-easing-function> =   
  linear( <linear-stop-list> )    
  
<cubic-bezier-easing-function> =   
  ease                                                |  
  ease-in                                             |  
  ease-out                                            |  
  ease-in-out                                         |  
  cubic-bezier( <number [0,1]> , <number> , <number [0,1]> , <number> )    
  
<step-easing-function> =   
  step-start                             |  
  step-end                               |  
  steps( <integer> , <step-position>? )    
  
<linear-stop-list> =   
  [ <linear-stop> ]#    
  
<step-position> =   
  jump-start  |  
  jump-end    |  
  jump-none   |  
  jump-both   |  
  start       |  
  end           
  
<linear-stop> =   
  <number>               &&  
  <linear-stop-length>?    
  
<linear-stop-length> =   
  <percentage>{1,2}    
  
```

Examples
--------

### Basic example

In this example, when the user hovers over the element, there is a one-second delay before the four-second `font-size` transition occurs.

#### HTML


```html
<a class="target">Hover over me</a>
```


#### CSS

We include two `<time>` values. In the `transition` shorthand, the first `<time>` value is the `transition-duration`. The second time value is the `transition-delay`. Both default to `0s` if omitted.


```css
.target {
  font-size: 14px;
  transition: font-size 4s 1s;
}

.target:hover {
  font-size: 36px;
}
```

Specifications
--------------

| Specification |
| --- |
| CSS Transitions # transition-shorthand-property |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* CSS transitions module
* Using CSS transitions
* `TransitionEvent`