The Wayback Machine - https://web.archive.org/web/20241007140553/https://www.geeksforgeeks.org/css-transition-property/
Open In App

CSS transition Property

Last Updated : 29 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The transition-property CSS property sets which CSS properties will have a transition effect, enabling smooth animations for specified properties when they change, without altering the layout or requiring JavaScript.

This property is a combination of four sub-properties

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

Note: The transition effect can be defined in two states (hover and active) using pseudo-classes like hover or: active or classes dynamically set by using JavaScript.

Syntax

selector {
transition: <transition-property>
<transition-duration>
<transition-timing-function>
<transition-delay>;
}

Note: If any of the values are not defined then the browser assumes the default values.

Property Values

PropertyDescription
transition-propertySpecifies the CSS properties to which a transition effect should be applied.
transition-durationSpecifies the length of time a transition animation should take to complete.
transition-timing-functionSpecifies the speed curve of the transition effect.
transition-delaySpecifies the delay before the transition effect starts.

Example 1: Background Color Transition

In this example we creates a blue box that transitions to green when hovered over, utilizing the CSS transition property to animate the color change over 0.5 seconds with an ease timing function.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, 
                   initial-scale=1.0">
    <title>CSS Transition Example </title>
    <style>
        .box {
            width: 100px;
            height: 100px;
            background-color: blue;
            transition: background-color 0.5s ease;
        }

        .box:hover {
            background-color: green;
        }
    </style>
</head>

<body>
    <h2>Css transition property</h2>
    <div class="box"></div>
</body>

</html>

Output:

gif5

CSS transition Property Example Output

Example 2: Width and Height Transition

This example demonstrates the use of the transition property to change the width and height

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, 
                   initial-scale=1.0">
    <title>CSS Transition property </title>
    <style>
        .rectangle {
            width: 100px;
            height: 50px;
            background-color: red;
            transition: width 0.3s ease, height 0.3s ease;
        }

        .rectangle:hover {
            width: 200px;
            height: 100px;
        }
    </style>
</head>

<body>
    <h2>CSS transition property</h2>
    <div class="rectangle">
        <p>Width and Height Transition</p>
    </div>
</body>

</html>

Output:

gif6

CSS transition Property Example Output

Supported Browsers

The browser supported by transition property are listed below: 

CSS transition Property – FAQs

What is the purpose of the transition property in CSS?

The transition property allows you to define smooth changes of CSS properties from one state to another over a specified duration.

Which CSS properties can be transitioned using the transition property?

Most animatable CSS properties, such as color, background-color, height, width, etc., can be transitioned using the transition property.

How do I specify multiple transitions on the same element?

You can specify multiple transitions by separating them with commas. For example: transition: color 2s, background-color 1s;

Is it possible to have different transition durations for different properties?

Yes, you can specify different durations for each property by defining them separately in the transition shorthand property.

What happens if a transition is defined on a property that is not animatable?

If a transition is set on a non-animatable property, the transition will not occur, and the property will change immediately without animation.



Previous Article
Next Article

Similar Reads

CSS transition-property Property
The transition effect is used to display the change in the property of an element over a specified duration. The transition-property property is used to specify the name of the CSS property for which the transition effect will occur. Syntax: transition-property: none | all | property | initial | inherit;Property values: none: This value is used to
5 min read
What is the purpose of the Transition Property in CSS ?
The Transition property in CSS is used to smoothly animate changes in property values over a specified duration. It enhances the user experience by creating fluid and visually appealing transitions between different states of an element. The transition property is applied to the element being animated, specifying the properties to transition, the d
1 min read
CSS transition-timing-function Property
The transition-timing-function property specifies the speed curve of the transition effect. It determines how CSS properties change values over time during transitions. This curve, or easing function, defines the rate of change, influencing the smoothness and perception of animation transitions on web elements. Syntaxanimation-timing-function: <
2 min read
How to apply Transition on CSS Display Property ?
This article will guide the implementation of basic Transition on CSS Display Property, aiming to achieve seamless and aesthetically pleasing transitions when altering the visibility of an element. Upon clicking the button, the image smoothly transitions to create a visually engaging effect. Table of Content Opacity and Display Transition Technique
5 min read
Tailwind CSS Transition Property
This class accepts lots of value in tailwind CSS in which all the properties are covered in class form. The transition-property class is used to specify the name of the CSS property for which the transition effect will occur. In CSS, we have done that by using the CSS transition-property. Transition Property classes: transition-none: This value is
2 min read
CSS transition-delay Property
The transition-delay property in CSS specifies the delay time before a transition effect begins. It controls when the transition starts after a change has been initiate Use transition-delay to sequence transitions or to synchronize them with other animations or events on the page. It allows for precise timing control over animation effects. Syntaxt
3 min read
CSS transition-duration Property
The transition-duration property in CSS specifies the duration over which a transition effect occurs. It defines how long it takes for a CSS property to change from one state to another. Syntaxtransition-duration: time | initial | inherit;Property Valuestime: Specifies the duration of the transition effect in seconds (s) or milliseconds (ms).initia
3 min read
Ember.js Transition from Property
Ember.js is an open-source JavaScript framework used for developing large client-side web applications which is based on Model-View-Controller (MVC) architecture. Ember.js is one of the most widely used front-end application frameworks. It is made to speed up development and increase productivity. Currently, it is utilized by a large number of webs
2 min read
Ember.js Transition data Property
Ember.js is an open-source JavaScript framework used for developing large client-side web applications which is based on Model-View-Controller (MVC) architecture. Ember.js is one of the most widely used front-end application frameworks. It is made to speed up development and increase productivity. Currently, it is utilized by a large number of webs
2 min read
HTML DOM Style transition Property
The HTML DOM Style Property is used to change the appearance of any DIV element. It changes the appearance whenever the mouse hovers over that element.  SyntaxFor return the transition property:object.style.transitionFor set the transition property:object.style.transition = "property duration timing-function delay | initial | inherit"Return ValuesI
2 min read
How to set width transition in Tailwind CSS ?
In Tailwind CSS, the transition utility is used to apply a width transition to an element. The transition utility accepts a list of properties, duration, and timing functions for the transition. Approach: To create a width transition, we can use the transition class and a duration and easing function to animate the width change. For example, we can
2 min read
How to smoothly transition CSS background images using jQuery?
In this article, we will learn to implement a smooth transition of background images using jQuery and CSS. Approach: First, we add a transparent background image using the background-image property in CSS in the style tag. background-image: url(white.jpg); For the transition background image, we use the transition property in CSS and add a transiti
2 min read
How CSS transition work with linear gradient background button?
In CSS, you can smoothly make transitions between two or more colors. CSS has two types of gradients: Linear gradient: It goes down/up/left/right/diagonally and makes smooth transitions of colors. To make a linear transition you first have to choose two color stops. Color stops are the color among which you want to make the transitions. You can als
1 min read
Difference between animation and transition in CSS
CSS transitions allow you to change property values smoothly, but they always need to be triggered like hover. Property changes do not take effect immediately. Over a period of time, the property changes take place. For example, if you change the color of an element from white to black, the change occurs instantly. The CSS changes occur at time int
3 min read
How to set Transition duration in Tailwind CSS ?
In this article, we will see how to set transition duration in Tailwind CSS. Tailwind CSS is a highly customizable, utility-first CSS framework from which we can use utility classes to build any design. Transition duration class accepts lots of value in tailwind CSS in which all the properties are covered in class form. The transition-duration clas
2 min read
How to create a Smooth Transition on hover using CSS ?
Creating a smooth transition on hover in CSS involves using the transition property to define the property being animated and the duration of the transition. This effect is commonly used to make changes to an element's appearance smooth and visually appealing when a user hovers over it. Syntax:/* Example of creating a smooth transition on hover */.
1 min read
How to Make Z-Index Transition on Image using HTML & CSS ?
By using the z-index property, CSS provides the ability to position elements above or below other elements. We can utilize the z-index property to create a seamless transition effect for elements when there is a change in the z-index value after a certain delay. This article will specifically focus on how to modify the z-index values for images so
4 min read
How to Create a Color Transition Effect in CSS ?
Color transition in CSS smoothly blends colors, creating seamless transitions that captivate users and enhance the overall user experience. There are several methods to achieve color transition effects in CSS. These include CSS gradients, CSS animations, CSS variables, and CSS transitions. Use the below methods for creating color transition effects
2 min read
How to Create a Transition Effect on Hover Pagination using CSS ?
In web development, pagination is a common feature used to navigate through a large set of data or content. Adding a transition effect on hover to pagination buttons can enhance user interaction and provide visual feedback. ApproachIn this approach, we are going to use CSS transitions. It enables smooth changes in CSS property values over a specifi
1 min read
Transition shorthand with multiple properties in CSS?
The transition shorthand in CSS allows specifying multiple properties for smooth transitions between different states or values. The transition property in CSS is used to create transitions in an element, enabling changes to occur smoothly over a specified duration. This article demonstrates how to use the transition shorthand to apply hover effect
2 min read
Design a Image Hover Effect Color Transition template using HTML and CSS
The article uses HTML and CSS to create the template for an Image Hover Effect with Color Transition. This template adds an interactive element to your web design by smoothly transitioning colors when users hover over an image. You can create a dynamic effect that enhances visual engagement by utilizing HTML for structure and CSS for styling. Upon
2 min read
How to use Animation and Transition Effects in CSS ?
With the help of CSS, you may design impressive visual effects for your website. Animation and transition effects are two common ways to add animation and visual effects to a web page. By attracting users' attention and directing them through your material, these effects may make your website more dynamic and engaging. In this article, we will see
4 min read
How to Linearly Transition the removal of a DOM element using CSS and JavaScript ?
For a particular HTML/DOM element, our job is to remove it and add a transition to the process of removal. Eventually, as soon as the trigger button is clicked, the DOM element should translate towards the right and finally be removed from sight as well as from the DOM. Transitioning elements using CSS often confuses developers. There can be many v
2 min read
Tailwind CSS Transition Timing Function
This class accepts lots of value in tailwind CSS in which all the properties are covered in class form. The transition timing function class is used to specify the time an animation uses to change from one set of CSS transitions to another. In CSS, we have done that by using the CSS transition-timing-function. Transition timing function classes: ea
2 min read
How to Add Transition on Hover Using CSS?
Transitions are the CSS technique used to create smooth changes between property values over a specified duration. By defining a transition, you can animate properties such as color, size, or position, making changes appear gradual rather than abrupt. For hover effects, transitions can enhance user experience by smoothly altering styles when a user
3 min read
Tailwind CSS Transition Delay
This class accepts lots of value in tailwind CSS in which all the properties are covered as in class form. The transition delay class is used to specify the length of time (in seconds or milliseconds) to start the transition effect. In CSS, we have done that by using the CSS transition-delay. Transition Delay classes:delay-75: This class is used to
2 min read
Tailwind CSS Transition Duration
This class accepts lots of value in tailwind CSS in which all the properties are covered in class form. The transition-duration class is used to specify the length of time (in seconds or milliseconds) to complete the transition effect. In CSS, we have done that by using the CSS transition-duration. Transition Duration classes:duration-75: This clas
2 min read
How to make transition height from 0 to auto using CSS ?
In this article, we are going to discuss how we can perform the transition from "height: 0;" to "height: auto;" using CSS. The problem with directly transitioning to height: auto is that there is no transition, and it changes promptly. Instead, we need a transition in which the element or a container will change its height.  Syntax: transition: [pr
3 min read
ReactJS | Transition Group
While React manages different components and their behavior to make any web app interactive it contains no methodology of adding aesthetics to the app itself. The animation is considered to be one of the most used methods to add aesthetics to an app, we can add animation to a React App using an explicit group of components known as the React Transi
4 min read
jQuery Mobile Popup Widget transition Option
jQuery Mobile is a web-based technology used to make responsive content that can be accessed on all smartphones, tablets, and desktops. In this article, we will be using jQuery Mobile Popup Widget transition option to set the default transition for the popup. The default value will result in no transition. Syntax: $("selector").popup({ transition:
1 min read