Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

Transition in CSS: Transition Transition Effect in CSS

Understand Transition in CSS: Transition Transition Effect in CSS with clear explanations, practical examples, and useful tips. This updated guide covers...

Table of Contents

Transition in CSS: Transition Transition Effect in CSS is easier to understand when the core ideas are paired with practical examples. The sections below explain the topic clearly, highlight useful steps, and point out details that can prevent common errors.

Transition properties in CSS are widely used in web design to create beautiful transition effects on websites easily.

Transition in CSS: Transition Transition Effect in CSS example image 1

Transition works by changing the attribute value smoothly from one value to another in a certain time period. Commonly used parameters:

  • transition-delay: the time interval for each transition effect.
  • transition-duration: the duration of the transition.
  • transition-property: attribute to convert.
  • transition-timing-function: conversion speed occurs.

How to use Transition in CSS

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

  • CSS properties want to add effects
  • Duration of conversion (duration).

Note: If the duration is not specified, the conversion will not be smooth and smooth because the default value is 0.

Change the value of an attribute

Example: Element

purple 100px * 100px, we specify the Transition effect for width attributes, with a duration of 2 seconds:
 div { 
  width: 100px; 
  height: 100px; 
  background: purple; 
  -webkit-transition: width 2s; /* Safari */ 
  transition: width 2s; 
 } 

The transition effect will take place when the width attribute is changed in value.

 div:hover { 
  width: 300px; 
 } 

Transition in CSS: Transition Transition Effect in CSS example image 2

Full code:

Transition properties

Hover over the element to see the transition effect:

Note : When the cursor moves away from the element, it will gradually change back to the original type.

Change the value of multiple attributes

Example: Add transition effects for both width and height attributes, with a duration of 2 seconds for width and 4 seconds for height.

 div { 
  -webkit-transition: width 2s, height 4s; /* Safari */ 
  transition: width 2s, height 4s; 
 } 

Transition in CSS: Transition Transition Effect in CSS example image 3

Conversion speed

The transition-timing-function attribute is used to determine the rate of change when converting.

The values available are as follows:

  • ease : create transition effect at the beginning, then slowly and quickly and slowly end slowly (default value).
  • linear: create transition effect from start to finish at the same speed.
  • ease-in: create a slow transition effect at the start.
  • ease-out: create a slow transition effect at the end.
  • ease-in-out: create a slow transition effect at the beginning and end.
 #div1 {transition-timing-function: linear;} 
 #div2 {transition-timing-function: ease;} 
 #div3 {transition-timing-function: ease-in;} 
 #div4 {transition-timing-function: ease-out;} 
 #div5 {transition-timing-function: ease-in-out;} 

Transition in CSS: Transition Transition Effect in CSS example image 4 Transition in CSS: Transition Transition Effect in CSS example image 5 Transition in CSS: Transition Transition Effect in CSS example image 6 Transition in CSS: Transition Transition Effect in CSS example image 7 Transition in CSS: Transition Transition Effect in CSS example image 8

Run the following code yourself to see the difference:

linear
 
ease
 
ease-in
 
ease-out
 
ease-in-out
 

Delay of Transition effect

The transition-delay attribute helps determine the delay between the time a property changes and when the transition actually starts.

Example : Delay of 1 second before starting conversion.

 div { 
  -webkit-transition-delay: 1s; /* Safari */ 
  transition-delay: 1s; 
 } 

Transition in CSS: Transition Transition Effect in CSS example image 9

When dragging the mouse, the effect does not happen immediately but will be delayed 1s is the time that we set for it.

Full code:

The transition-delay attribute

Hover over the element to see the transition effect:

Combine Transition with Transform

Transform Tipsmake learned in the previous lesson, go to the 2D Transform review here and 3D Transform here.

Combining Transition with Transform together will create extremely beautiful transition effect.

 div { 
  -webkit-transition: width 2s, height 2s, -webkit-transform 2s; /* Safari */ 
  transition: width 2s, height 2s, transform 2s; 
 } 

Transition in CSS: Transition Transition Effect in CSS example image 10

Transition + Transform

The same effects at the beginning of the lesson also use a combination of Transition and Transform. You add some properties to change the color, style, font size. to your liking. The code below for your reference.

Transition in CSS: Transition Transition Effect in CSS example image 11

TipsMake.com

Previous lesson: 3D Transform in CSS

Next lesson: Animation animation effect in CSS

FAQ

How to use Transition in CSS?

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

What should you know about transition properties?

Hover over the element to see the transition effect:

What should you know about change the value of multiple attributes?

Example: Add transition effects for both width and height attributes, with a duration of 2 seconds for width and 4 seconds for height.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.