| 
									
										
										
										
											2018-10-12 15:37:13 -04:00
										 |  |  | --- | 
					
						
							|  |  |  | title: Transition | 
					
						
							|  |  |  | --- | 
					
						
							|  |  |  | <!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds  --> | 
					
						
							|  |  |  | ## Transition
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The `transition` property allows you to change property values smoothly (from one value to another), over a given duration.  | 
					
						
							|  |  |  | ```css  | 
					
						
							|  |  |  |   transition: all 300ms; | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ### Transition on Several Property Values
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | You can change multiples property values with transition property. | 
					
						
							|  |  |  | ```css  | 
					
						
							|  |  |  |   transition: width 300ms, height 2s; | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2018-11-05 02:26:25 +11:00
										 |  |  | ## Sub-Property
 | 
					
						
							| 
									
										
										
										
											2018-10-12 15:37:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-05 02:26:25 +11:00
										 |  |  | To create a CSS transition, we have different sub-properties for the transition property in CSS : | 
					
						
							| 
									
										
										
										
											2018-10-12 15:37:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-05 02:26:25 +11:00
										 |  |  | • `transition-delay`<br> | 
					
						
							|  |  |  | • `transition-duration`<br> | 
					
						
							|  |  |  | • `transition-property`<br> | 
					
						
							|  |  |  | • `transition-timing-function` | 
					
						
							| 
									
										
										
										
											2018-10-12 15:37:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-05 02:26:25 +11:00
										 |  |  | ### Delay
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The `transition-delay` property defines the delay (in seconds) before the transition is played. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```css | 
					
						
							|  |  |  | /* 2 seconds delay */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | div { | 
					
						
							|  |  |  |   transition-delay: 2s; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-10-12 15:37:13 -04:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-05 02:26:25 +11:00
										 |  |  | ### Duration
 | 
					
						
							| 
									
										
										
										
											2018-10-12 15:37:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-05 02:26:25 +11:00
										 |  |  | The `transition-duration` property defines the duration (in seconds) of the transition. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```css | 
					
						
							|  |  |  | /* 2 seconds duration */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | div { | 
					
						
							|  |  |  |   transition-duration: 2s; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | ### Property
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The `transition-property` property defines the CSS property that will be affected in the transition. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```css | 
					
						
							|  |  |  | /* The transition will be on the width property */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | div { | 
					
						
							|  |  |  |   transition-property: width; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ### Timing-function
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The `transition-timing-function` property defines the speed of the transition. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```css | 
					
						
							|  |  |  | /* The transition speed */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | div { | 
					
						
							| 
									
										
										
										
											2018-10-12 15:37:13 -04:00
										 |  |  |   transition-timing-function: linear; | 
					
						
							| 
									
										
										
										
											2018-11-05 02:26:25 +11:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-10-12 15:37:13 -04:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2018-11-05 02:26:25 +11:00
										 |  |  | #### Different values of `transition-timing-function`
 | 
					
						
							| 
									
										
										
										
											2018-10-12 15:37:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-05 02:26:25 +11:00
										 |  |  | • `ease` - specifies a transition effect with a slow start, then fast, then end slowly (this is default)<br> | 
					
						
							|  |  |  | • `linear` - specifies a transition effect with the same speed from start to end<br> | 
					
						
							|  |  |  | • `ease-in` - specifies a transition effect with a slow start<br> | 
					
						
							|  |  |  | • `ease-out` - specifies a transition effect with a slow end<br> | 
					
						
							|  |  |  | • `ease-in-out` - specifies a transition effect with a slow start and end<br> | 
					
						
							|  |  |  | • `cubic-bezier(n,n,n,n)` - lets you define your own values in a cubic-bezier function | 
					
						
							| 
									
										
										
										
											2018-10-12 15:37:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-05 02:26:25 +11:00
										 |  |  | ## Syntax
 | 
					
						
							| 
									
										
										
										
											2018-10-12 15:37:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 16:17:38 +08:00
										 |  |  | ### Transition Delay
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Setting a transition delay determines when the transition will start. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```css | 
					
						
							|  |  |  | transition-delay: 1s; | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ### Transition Shorthand
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-05 02:26:25 +11:00
										 |  |  | ```css | 
					
						
							|  |  |  | transition: property name / duration / timing function / delay ; | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2018-12-25 16:17:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-05 02:26:25 +11:00
										 |  |  | #### Example
 | 
					
						
							|  |  |  | ```css | 
					
						
							|  |  |  | transition: width 2s linear 2s; | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2018-10-12 15:37:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | #### More Information:
 | 
					
						
							|  |  |  | <!-- Please add any articles you think might be helpful to read before writing the article --> | 
					
						
							| 
									
										
										
										
											2018-12-25 16:17:38 +08:00
										 |  |  | * [MDN - transition](https://developer.mozilla.org/en-US/docs/Web/CSS/transition) | 
					
						
							|  |  |  | * [Easings reference](http://easings.net/en) |