CSS3 Transition
CSS3 Transitions
In CSS3, to add certain effects, we can transition from one style to another without using Flash animations or JavaScript. Move the mouse over the following elements:
Hover over the following elements:
Transition
Browser Support
The numbers in the table indicate the first browser version number that supports the property.
The number immediately preceding -webkit-, -ms-, or -moz- is the first browser version number that supports the prefixed property.
| Property | |||||
|---|---|---|---|---|---|
| transition | 26.0 4.0 -webkit- |
10.0 | 16.0 4.0 -moz- |
6.1 3.1 -webkit- |
12.1 10.5 -o- |
| transition-delay | 26.0 4.0 -webkit- |
10.0 | 16.0 4.0 -moz- |
6.1 3.1 -webkit- |
12.1 10.5 -o- |
| transition-duration | 26.0 4.0 -webkit- |
10.0 | 16.0 4.0 -moz- |
6.1 3.1 -webkit- |
12.1 10.5 -o- |
| transition-property | 26.0 4.0 -webkit- |
10.0 | 16.0 4.0 -moz- |
6.1 3.1 -webkit- |
12.1 10.5 -o- |
| transition-timing-function | 26.0 4.0 -webkit- |
10.0 | 16.0 4.0 -moz- |
6.1 3.1 -webkit- |
12.1 10.5 -o- |
How does it work?
CSS3 transitions are effects that gradually change an element from one style to another.
To achieve this, two things must be specified:
- Specify the CSS property to which you want to add the effect.
- Specify the duration of the effect.
Example
A transition effect applied to the width property, with a duration of 2 seconds:
Note:If the duration is not specified, the transition will have no effect, because the default value is 0.
The effect changes when the value of the specified CSS property changes. A typical CSS property change occurs when the user's mouse hovers over an element:
Example
Specify when the mouse pointer hovers (:hover) over the <div> element:
Try it Yourself »
Note:When the mouse cursor moves over the element, it gradually transitions from its original style.
Multiple Changes
To add transition effects for multiple styles, add the properties separated by commas:
Example
Added width, height, and transform effects:
Try it Yourself »
Transition Property
The following table lists all the transition properties:
| Property | Description | CSS |
|---|---|---|
| transition | Shorthand property, used to set four transition properties in one property. | 3 |
| transition-property | Specifies the name of the CSS property to which the transition is applied. | 3 |
| transition-duration | Defines the time spent on the transition effect. The default is 0. | 3 |
| transition-timing-function | Specifies the timing curve of the transition effect. The default is "ease". | 3 |
| transition-delay | Specifies when the transition effect will start. The default is 0. | 3 |
The following two examples set all transition properties:
Example
Use all transition properties in one example:
Try it Yourself »
Example
Same transition effect as the example above, but using the shorthand transition property:
Try it Yourself »