Easy Tutorial
❮ Css3 Fonts Css3 Pr Rotation Point ❯

CSS3 Transition


CSS3 Transition

In CSS3, we can add effects that transition from one style to another without using Flash animations or JavaScript. Hover your mouse over the element below:


Hover your mouse over the element below:


Browser Support

The numbers in the table specify the first browser version that fully supports the property.

The numbers preceding -webkit-, -ms-, or -moz- indicate the first browser version that supports the prefixed property.

Property Chrome IE Firefox Safari Opera
transition 26.0 <br>4.0 -webkit- 10.0 16.0 <br>4.0 -moz- 6.1 <br>3.1 -webkit- 12.1 <br>10.5 -o-
transition-delay 26.0 <br>4.0 -webkit- 10.0 16.0 <br>4.0 -moz- 6.1 <br>3.1 -webkit- 12.1 <br>10.5 -o-
transition-duration 26.0 <br>4.0 -webkit- 10.0 16.0 <br>4.0 -moz- 6.1 <br>3.1 -webkit- 12.1 <br>10.5 -o-
transition-property 26.0 <br>4.0 -webkit- 10.0 16.0 <br>4.0 -moz- 6.1 <br>3.1 -webkit- 12.1 <br>10.5 -o-
transition-timing-function 26.0 <br>4.0 -webkit- 10.0 16.0 <br>4.0 -moz- 6.1 <br>3.1 -webkit- 12.1 <br>10.5 -o-

How Does It Work?

CSS3 transitions allow elements to gradually change from one style to another.

To achieve this, you must specify two things:

Example

Transition effect applied to the width property, lasting 2 seconds:

div {
    transition: width 2s;
    -webkit-transition: width 2s; /* Safari */
}

Note: If no duration is specified, the transition will have no effect, as the default value is 0.

The effect changes when the specified CSS property's value changes. A typical change occurs when the user hovers the mouse over an element:

Example

Specifies that when the mouse pointer hovers over a <div> element:

div:hover {
    width: 300px;
}

Note: When the mouse cursor moves over the element, it gradually changes its original style.


Multiple Changes

To add multiple style transition effects, separate the properties with commas:

Example

Adds transition effects to width, height, and transform:

div {
    transition: width 2s, height 2s, transform 2s;
    -webkit-transition: width 2s, height 2s, -webkit-transform 2s;
}

Transition Properties

The following table lists all the transition properties:

Property Description CSS
transition A shorthand property for setting the four transition properties. 3
transition-property Specifies the name of the CSS property to which the transition is applied. 3
transition-duration Defines how long the transition effect should last. The default is 0. 3
transition-timing-function Specifies the speed curve of the transition effect. The default is "ease". 3
transition-delay Specifies when the transition effect should start. The default is 0. 3

The following two examples set all transition properties:

Example

Using all transition properties in one example:

div {
    transition-property: width;
transition-duration: 1s;
transition-timing-function: linear;
transition-delay: 2s;
/* Safari */
-webkit-transition-property: width;
-webkit-transition-duration: 1s;
-webkit-transition-timing-function: linear;
-webkit-transition-delay: 2s;

Example

The same transition effect as above, but using the shorthand transition property:

div {
    transition: width 1s linear 2s;
    /* Safari */
    -webkit-transition: width 1s linear 2s;
}
❮ Css3 Fonts Css3 Pr Rotation Point ❯