CSS Properties
CSS transition-delay Property
Photo Credit to CodeToFun
🙋 Introduction
The transition-delay
property in CSS is used to specify the amount of time to wait before the transition effect starts.
This property is useful for creating smoother animations and for controlling the timing of transitions on your web page. By adjusting the transition-delay
, you can create more dynamic and visually appealing effects for your users.
💡 Syntax
The syntax for the transition-delay
property is straightforward. It can be applied to any element that supports transitions.
element {
transition-delay: time;
}
Here, time can be specified in seconds (s) or milliseconds (ms).
🎛️ Default Value
The default value of the transition-delay
property is 0s, meaning the transition starts immediately.
🏠 Property Values
Value | Description |
---|---|
time | Specifies the amount of time to wait before the transition effect starts. This can be in seconds (e.g., 2s) or milliseconds (e.g., 200ms). |
📄 Example
In this example, we'll create a simple transition effect where the background color of a div changes after a delay of 2 seconds when the user hovers over it.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS transition-delay Example</title>
<style>
.box {
width: 100px;
height: 100px;
background-color: blue;
transition: background-color 1s;
transition-delay: 2s;
}
.box:hover {
background-color: red;
}
</style>
</head>
<body>
<h1>Transition Delay Example</h1>
<div class="box"></div>
</body>
</html>
🖥️ Browser Compatibility
The transition-delay
property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.
🎉 Conclusion
The transition-delay
property is a powerful tool for web developers looking to create timed transitions and animations.
By adjusting the delay, you can control the timing of your effects, making your web pages more engaging and visually appealing. Experiment with different delay times and see how this property can enhance the user experience on your website.
👨💻 Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (CSS transition-delay Property), please comment here. I will help you immediately.