Tillitsdone
down Scroll to discover

CSS transition-delay Enhance User Experience with Delayed Transitions

The CSS transition-delay property specifies the amount of time to wait before starting a transition effect.

It can be zero, positive, or negative, offering precise control over animation timing.
thumbnail

Introduction to transition-delay

The transition-delay property in CSS lets you control when a transition starts. This can make your animations more dynamic and engaging.

How transition-delay Works

  • Single Delay: You can delay a transition by a specific amount of time.
  • Multiple Delays: You can set different delays for different properties.

Basic Usage

For example, you can delay a transition by 2 seconds:

transition-delay: 2s; /* Delays the transition by 2 seconds */

Multiple Delays

You can also set different delays for different properties:

transition-property: background-color, font-size, transform;
transition-delay: 0.5s, 1s, 2s; /* Different delays for different properties */

In this example:

  • background-color transition starts after a 0.5-second delay.
  • font-size transition starts after a 1-second delay.
  • transform transition starts after a 2-second delay.

Global Values

Besides time values, transition-delay can take global values like initial, inherit, unset, revert, and revert-layer.

transition-delay: inherit; /* Inherits the delay value from the parent element */

Examples

Example 1: Basic Delay

HTML

<div class="box">Hover over me!</div>

CSS

.box {
width: 100px;
height: 100px;
background-color: red;
transition-property: background-color;
transition-duration: 2s;
transition-delay: 2s; /* Delay the transition by 2 seconds */
}
.box:hover {
background-color: blue;
}

Result

When you hover over the .box element, the background color changes to blue after a 2-second delay.

Example 2: Multiple Delays

HTML

<div class="box">Hover over me!</div>

CSS

.box {
width: 100px;
height: 100px;
background-color: red;
font-size: 16px;
transform: scale(1);
transition-property: background-color, font-size, transform;
transition-duration: 2s;
transition-delay: 0.5s, 1s, 2s; /* Different delays for different properties */
}
.box:hover {
background-color: blue;
font-size: 24px;
transform: scale(1.5);
}

Result

When you hover over the .box element:

  • The background color changes to blue after a 0.5-second delay.
  • The font size increases to 24px after a 1-second delay.
  • The scale increases to 1.5 after a 2-second delay.

Example 3: Negative Delay

HTML

<div class="box">Hover over me!</div>

CSS

.box {
width: 100px;
height: 100px;
background-color: red;
transition-property: background-color;
transition-duration: 2s;
transition-delay: -1s; /* Start the transition partway through */
}
.box:hover {
background-color: blue;
}

Result

Hovering over the box will change its background color to blue immediately, but it will appear as if the transition had already been running for 1 second.

Browser Compatibility

The transition-delay property is widely supported across modern browsers:

  • Google Chrome: 26.0+ (March 2013)
  • Microsoft Edge: 12.0+
  • Mozilla Firefox: 16.0+ (October 2012)
  • Internet Explorer: 10.0+ (September 2012)
  • Opera: 12.1+ (November 2012)
  • Safari: 6.1+ (June 2013)

Resources

To learn more about CSS transitions, check out these resources:

  • [Using CSS transitions]WebsiteUrl
  • [TransitionEvent API]WebsiteUrl
  • CSS Transitions Module
  • [CSS transition-property]WebsiteUrl
  • [CSS transition-duration]WebsiteUrl
  • [CSS transition-timing-function]WebsiteUrl

Formal Syntax

The formal syntax for the transition-delay property is:

transition-delay: <time>[, <time>]*
  • <time>: The amount of time to wait before the transition starts (e.g., 2s or 500ms).
  • ,: Separates multiple delay values for different properties.

Example

transition-delay: 2s; /* Delays the transition by 2 seconds */
transition-delay: 0.5s, 1s, 2s; /* Different delays for different properties */

Summary

  • Single Delay: Delays all transitions by the same amount.
  • Multiple Delays: Sets different delays for different properties.
  • Global Values: Can use values like inherit to inherit from the parent element.

Using these features, you can control the timing of your transitions to create dynamic and visually appealing effects.

Values

The transition-delay property in CSS accepts several values that dictate the timing of transitions. These values provide flexibility and control over when a transition effect starts. Here are the key values you can use:

<time>

Specifies the amount of time to wait before the transition effect starts. This value can be expressed in seconds (s) or milliseconds (ms).

  • 0s or 0ms: Starts the transition immediately.
  • Positive value (e.g., 2s, 500ms): Delays the start of the transition by the specified duration.
  • Negative value (e.g., -1s, -200ms): Starts the transition immediately but partway through the effect, as if the transition had already been running for the given time.
transition-delay: 2s; /* Delays the transition by 2 seconds */
transition-delay: 0.5s; /* Delays the transition by 0.5 seconds */
transition-delay: -1s; /* Starts the transition partway through, as if it had been running for 1 second */

initial

Sets the transition-delay property to its default value, which is 0s. This value can be used to reset the delay to its initial state.

transition-delay: initial; /* Sets the delay to its default value (0s) */

inherit

Inherits the transition-delay value from the parent element. This is useful when you want to maintain consistency in transition delays across nested elements.

transition-delay: inherit; /* Inherits the delay value from the parent element */

unset

Resets the transition-delay property to its natural value, which means it will act as if the property is not set and fall back to its default or inherited value.

transition-delay: unset; /* Resets the property to its natural value */

revert

Reverts the transition-delay property to the value specified by the user-agent stylesheet. This can be useful for ensuring consistency with default browser styles.

transition-delay: revert; /* Reverts the property to the value specified by the user-agent stylesheet */

revert-layer

Reverts the transition-delay property to the value specified by the user-agent stylesheet while considering the current cascade layer. This provides more granular control over how styles are applied.

transition-delay: revert-layer; /* Reverts the property to the value specified by the user-agent stylesheet considering the current cascade layer */

By utilizing these values, you can precisely control the timing of transitions in your web designs. Whether you need immediate transitions, delayed effects, or animations that appear to have already started, the transition-delay property offers the flexibility to achieve your design goals.

Formal Definition

The transition-delay property in CSS specifies the duration to wait before starting a property’s transition effect when its value changes. This property is part of the CSS Transitions module, which allows you to animate changes to CSS properties over a specified duration.

Initial Value

  • Initial Value: 0s

The default value for transition-delay is zero seconds (0s), meaning that transitions will start immediately unless otherwise specified.

Applies To

  • Applies To: All elements, including ::before and ::after pseudo-elements.

The transition-delay property can be applied to any HTML element, as well as to the ::before and ::after pseudo-elements, allowing for flexible and creative animations across various parts of a web page.

Inherited

  • Inherited: No

The transition-delay property is not inherited from parent elements. Each element must have its own transition-delay value specified if a delay is desired.

Computed Value

  • Computed Value: As specified

The computed value of the transition-delay property is the same as the value specified in the CSS. This means that the delay time will be exactly what is defined in the stylesheet.

Animation Type

  • Animation Type: Not animatable

The transition-delay property itself is not animatable. It controls the timing of transitions but cannot be animated over time.

Formal Syntax

The formal syntax for the transition-delay property is as follows:

transition-delay: <time>[, <time>]*
  • <time>: Specifies the amount of time to wait before the transition effect starts. This can be in seconds (s) or milliseconds (ms).

Example

Here is an example of the formal syntax in use:

transition-delay: 2s; /* Delays the transition by 2 seconds */
transition-delay: 0.5s, 1s; /* Different delays for different properties */

In this example, the first line delays the transition by 2 seconds, while the second line specifies different delays for multiple properties.

By understanding the formal definition of the transition-delay property, web developers and designers can effectively control the timing of transitions, creating dynamic and engaging web experiences that meet modern design standards.

Delay Types

The transition-delay property in CSS offers flexibility in how transitions are timed, allowing for precise control over the start of animations. There are three main types of delays: zero delay, positive delay, and negative delay. Each type serves a specific purpose in web design and development.

Zero Delay

A zero delay, specified as 0s or 0ms, starts the transition effect immediately. This is the default behavior when no delay is specified.

transition-delay: 0s;

Positive Delay

A positive delay delays the start of the transition effect for the specified duration. This is useful for creating sequential animations or synchronizing transitions with other events on the page.

transition-delay: 2s;

Negative Delay

A negative delay starts the transition effect immediately but partway through the animation. This gives the impression that the transition has already been running for the given time, which can create unique and dynamic effects.

transition-delay: -1s;

By utilizing these different delay types, web developers and designers can create complex and engaging animations that enhance user experience. Whether you need immediate transitions, delayed effects, or animations that appear to have already started, the transition-delay property provides the tools to achieve your design goals.

icons/css-4.svg CSS Blogs
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
icons/logo-tid.svg

Talk with CEO

Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.