CSS3 transition Property
Example
Hover over a div element to gradually change the width from 100px to 300px:
div
{
width:
100
px
;
transition:
width
2
s
; -
webkit-transition:
width
2
s
;
/*
Safari
*/
}
div
:hover
{
width:
300
px
;
}
Try it »
Browser support
The numbers in the table indicate the first browser version that supports this property.
A number immediately before -webkit-, -ms-, or -moz- indicates the first browser version that supports that 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- |
Property definition and usage
The transition property lets you control transition effects when an element's state changes. It produces smooth transitions as an element changes from one style to another, such as from one color to another, or from hidden to visible.
This property contains four values:
-
transition-property: Specifies the name of the CSS property to transition. For example,
color,background-color, etc. -
transition-duration: Specifies the duration of the transition, in seconds or milliseconds.
-
transition-timing-function: Specifies the speed curve of the transition. It can be
linear(linear),ease(ease-in-out),ease-in(ease-in),ease-out(ease-out),ease-in-out(ease-in-out) and so on. -
transition-delay: Specifies the delay before the transition starts, in seconds or milliseconds.
Example
/* Apply the transition to all properties */
.element
{
transition
:
all 0.3s ease
;
}
/* Apply the transition to a specified property (color) */
.element
{
transition
:
color
0.3s ease-in-out
;
}
| Default value: | all 0 ease 0 |
|---|---|
| Inherited: | no |
| Version: | CSS3 |
| JavaScript syntax: | object.style.transition="width 2s" |
Syntax
transition:
property duration timing-function delay
;
| Value | Description |
|---|---|
| transition-property | Specifies the name of the CSS property for the transition effect |
| transition-duration | Specifies how many seconds or milliseconds the transition needs to complete |
| transition-timing-function | Specifies the speed curve of the transition effect |
| transition-delay | Defines when the transition effect starts |