WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

CSS3 Transitions


CSS3 Transitions

CSS3 transitions allow us to change from one property value to another over a given duration.

Example: It is a CSS3 transition effect:

CSS3

Browser Support for Transitions

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

Numbers followed by -webkit-, -moz-, or -o- specify the first version that worked with a prefix.

Property
transition 36.0
4.0 -webkit-
13.0 10.0 16.0
4.0 -moz-
6.1
3.1 -webkit-
13.1
10.5 -o-
transition-delay 36.0
4.0 -webkit-
13.0 10.0 16.0
4.0 -moz-
6.1
3.1 -webkit-
13.1
10.5 -o-
transition-duration 36.0
4.0 -webkit-
13.0 10.0 16.0
4.0 -moz-
6.1
3.1 -webkit-
13.1
10.5 -o-
transition-property 36.0
4.0 -webkit-
13.0 10.0 16.0
4.0 -moz-
6.1
3.1 -webkit-
13.1
10.5 -o-
transition-timing-function 36.0
4.0 -webkit-
13.0 10.0 16.0
4.0 -moz-
6.1
3.1 -webkit-
13.1
10.5 -o-

How to Use CSS3 Transitions?

To create a transition effect, you must specify two things:

  • the CSS property you want to add an effect to
  • the duration of the effect

The following example shows a 100px * 100px red <div> element. The <div> element has also specified a transition effect for the width property, with a duration of 3 seconds:

Example

div {
    width: 100px;
    height: 100px;
    background: red;
    -webkit-transition: width 3s; /* Safari */
    transition: width 3s;
}

The transition effect will start when the specified CSS property (width) changes value.

Now, let us specify a new value for the width property when a user mouses over the <div> element:

Example

div:hover {
    width: 300px;
}
Try it yourself »

Change Several Property Values

The following example adds a transition effect for both the width and height property, with a duration of 3 seconds for the width and 4 seconds for the height:

Example

div {
    -webkit-transition: width 3s, height 4s; /* Safari */
    transition: width 3s, height 4s;
}
Try it yourself »

Specify timing of the Transition

The transition-timing-function property specifies the speed curve of the transition effect.

The transition-timing-function property can have the following values:

  • ease - specifies a transition effect with a slow start, then fast, then end slowly (this is default)
  • linear - specifies a transition effect with the same speed from start to end
  • ease-in - specifies a transition effect with a slow start
  • ease-out - specifies a transition effect with a slow end
  • ease-in-out - specifies a transition effect with a slow start and end
  • cubic-bezier(n,n,n,n) - lets you define your own values in a cubic-bezier function

The following example shows the some of the different speed curves that can be used:

Example

#div1 {transition-timing-function: linear;}
#div3 {transition-timing-function: ease;}
#div3 {transition-timing-function: ease-in;}
#div4 {transition-timing-function: ease-out;}
#div5 {transition-timing-function: ease-in-out;}
Try it yourself »

Delay the Transition Effect

The transition-delay property specifies a delay (in seconds) for the transition effect.

The following example has a 1 second delay before starting:

Example

div {
    -webkit-transition-delay: 1s; /* Safari */
    transition-delay: 1s;
}
Try it yourself »

Transition + Transformation

The following example also adds a transformation to the transition effect:

Example

div {
    -webkit-transition: width 3s, height 3s, -webkit-transform 3s; /* Safari */
    transition: width 3s, height 3s, transform 3s;
}
Try it yourself »

More Transition Examples

The CSS3 transition properties can be specified one by one, like this:

Example

div {
    transition-property: width;
    transition-duration: 3s;
    transition-timing-function: linear;
    transition-delay: 1s;
}

Example

div {
    transition: width 3s linear 1s;
}
Try it yourself »