Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

CSS Dictionary

  1. Home
  2. CSS Dictionary
  3. transition

transition

Specifying the 'transition' property enables animation (change over time) when design changes occur due to 'pseudo-classes' or JavaScript.

Depending on the browser version, it may not work without vendor prefixes such as 'webkit', 'moz', 'ms', etc., so it is safer to include vendor prefixes when using this property. Also, note that the animation may be choppy depending on the PC specs.

In browsers that do not support 'transition', the change occurs normally (without animation) without any time-based transition.

Sample Code

transition: 0.5s;
-webkit-transition: 0.5s;
-moz-transition: 0.5s;
-ms-transition: 0.5s;

Available Sub-properties

PropertyInitial ValueDescription
transition-propertyallIndividually specifies the properties to apply the effect to.
transition-duration-Specifies the duration of the animation.
transition-delay0sSpecifies the delay from the event start to when the animation begins.
transition-timing-functioneaseSpecifies the timing and progression of the animation.

The above properties can all be specified together with the 'transition' property, separated by spaces. The order of specification is

  1. 'The property to animate' (transition-property)
  2. 'The animation duration' (transition-duration)
  3. 'The delay from the action to when the animation starts' (transition-delay)
  4. 'The timing and progression of the animation' (transition-timing-function)

Only the 'animation duration' value is required; the others can be omitted. Omitted values are treated as if the initial value was specified.

The following sample shows the syntax written out in plain English.

div {
	transition: property-to-animate(optional) animation-duration delay-before-animation-starts(optional) animation-timing(optional);
	-webkit-transition: property-to-animate(optional) animation-duration delay-before-animation-starts(optional) animation-timing(optional);
	-moz-transition: property-to-animate(optional) animation-duration delay-before-animation-starts(optional) animation-timing(optional);
	-ms-transition: property-to-animate(optional) animation-duration delay-before-animation-starts(optional) animation-timing(optional);
}

Browser Display Result

div {
	background: #f00;
	width: 200px;

	transition: 0.5s;
	-webkit-transition: 0.5s;
	-moz-transition: 0.5s;
	-ms-transition: 0.5s;
}
div:hover {
	width: 300px;
}

Browser Compatibility

Chrome Chrome
26+
25
24
23
22
21
20
19
18
↑ Requires prefix '-webkit-'
Firefox Firefox
16+
15
14
13
12
11
10
9
8
↑ Requires prefix '-moz-'
3 and earlier ×
Safari Safari
9+
8
7
6
5
4
↑ Requires prefix '-webkit-'
2 and earlier ×
Edge Edge
12+
Supported in all versions
IE IE
11
10
9 ×
8 ×
7 ×
6 ×
Opera Opera
12.1+
11
↑ Requires prefix '-o-'
9 and earlier ×
iOS Safari iOS Safari
9+
8
7
6
5
4
3
2
↑ Requires prefix '-webkit-'
1 and earlier ×
Android Android Browser
4.4+
2
↑ Requires prefix '-webkit-'
Chrome Android Chrome Android
Latest
Same support as desktop
Firefox Android Firefox Android
Latest
Same support as desktop

※ Version data is based on MDN / Can I Use.

Details

Specifying the 'transition' property enables animation (change over time) when design changes occur due to 'pseudo-classes' or JavaScript.

The following sample specifies each sub-property together. Since 'width' is specified as the 'property to animate', it does not apply to 'background'. Since '1s' is specified as the 'delay before animation starts', there is a 1-second lag from the event start to when the animation begins. 'ease-in' is specified as the 'animation timing' to change the movement of the animation.

div {
	background: #f00;
	width: 200px;

	transition: width 0.5s 1s ease-in;
	-webkit-transition: width 0.5s 1s ease-in;
	-moz-transition: width 0.5s 1s ease-in;
	-ms-transition: width 0.5s 1s ease-in;
}
div:hover {
	width: 300px;
	background: #ff0;
}

Multiple properties can be specified for the 'property to animate' by separating them with ','. Note that when specifying multiple items together, other values such as the 'delay before animation starts' must also be specified individually for each.

div {
	background: #f00;
	width: 200px;
	height: 100px;

	transition: width 0.5s ease-in, height 0.5s 1s ease-in;
	-webkit-transition: width 0.5s ease-in, height 0.5s 1s ease-in;
	-moz-transition: width 0.5s ease-in, height 0.5s 1s ease-in;
	-ms-transition: width 0.5s ease-in, height 0.5s 1s ease-in;
}
div:hover {
	width: 300px;
	height: 200px;
	background: #ff0;
}

Note that 'transition'-related properties must be specified on the element before the event starts. Specifying them after the event (e.g., in ':hover') will not work as expected.

All the samples so far have used CSS, but animation also works when design changes are made with JavaScript.
For smartphones, it is more common to use JavaScript events like 'touch' and 'flick' than pseudo-class events alone.

div {
	background: #f00;
	width: 200px;

	transition: 0.5s ease-in;
	-webkit-transition: 0.5s ease-in;
	-moz-transition: 0.5s ease-in;
	-ms-transition: 0.5s ease-in;
}

<script>
	window.addEventListener("load", function(){
		var elem = document.getElementById("test");
		if(elem){
			elem.addEventListener("mouseover", function(){
				this.style.width = "300px";
			}, false);
		}
	}, false);
</script>
<p>When you hover over the element, 'width' changes to 300px. Unlike CSS pseudo-classes, since JavaScript is used to change the width, it will not return to the original 200px. If you want to restore it, you need to implement that logic in JavaScript as well.</p>
<div id="test">When you hover, the width changes to 300px.</div>

If you find any errors or copyright issues, please .