🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to CSS Notes
Topic #136

CSS Transitions


CSS Transitions

CSS transitions allows you to change property values smoothly, over a given duration.

Mouse over the element below to see a CSS transition effect:


The CSS transition Property

To create a transition effect, you must specify the CSS property you want to add a transition to, and the duration of the transition.

The CSS transition property is a shorthand property for:

  • transition-property
  • transition-duration
  • transition-timing-function
  • transition-delay

CSS Transition Example

The following example shows a 100px * 100px

element. The
element has specified a transition effect for the width property, with a duration of 2 seconds:

Example

div
{
  width: 100px;
  height: 100px;

background-color: red;
  transition: width 2s;

}

How to Trigger the Transition

The transition is triggered when there is a change in the element's properties. This often happens within pseudo-classes (:hover, :active, :focus, or :checked).

So, from the code above, the transition effect will start when the width property changes value.

Now, we add a div:hover class that specifies a new value for the width property when a user mouses over the

element:

Example

div:hover
{

  width: 300px;

}

Notice that when the cursor mouses out of the element, it will gradually change back to its original style.


Change Multiple Property Values

You can change multiple properties by separating them by commas.

The following example adds a transition effect for the width, height, and background-color properties, with a duration of 2 seconds for the width, 4 seconds for the height, and 3 seconds for the background-color:

Example

div
{

  transition: width 2s, height 4s, background-color 3s;

}

CSS Transition Properties

The following table lists all the CSS transition properties:

Property Description
transition A shorthand property for setting the four transition properties into a single property
transition-delay Specifies a delay (in seconds) for the transition effect
transition-duration Specifies how many seconds or milliseconds a transition effect takes to complete
transition-property Specifies the name of the CSS property the transition effect is for
transition-timing-function Specifies the speed curve of the transition effect

Want to go beyond the notes?

Join CodingNow 2.0's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

CSS Transitions – FAQs

Quick answers about learning CSS Transitions in CSS.

This free note from CodingNow 2.0 explains CSS Transitions in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on CodingNow 2.0, including CSS Transitions, is 100% free with no signup required.
With focused practice, most students grasp CSS Transitions in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now