Open In App

CSS animation-delay Property

Last Updated : 23 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The animation-delay property specifies a delay for the start of an animation. Defined in seconds (s) or milliseconds (ms), this value determines how long to wait before beginning the animation. Negative values start the animation as if it had already been playing for the specified duration.

Syntax

animation-delay: time|initial|inherit;

Property Values

ValueDescription
timeOptional. Defines the number of seconds (s) or milliseconds (ms) to wait before the animation starts. Default is 0. Negative values are allowed and will start the animation as if it had already been playing for N seconds/milliseconds.
initialSets the property to its default value.
inheritInherits the property from its parent element.

Example: This example demonstrates the animation-delay property in CSS. The animation on the second <h2> tag is delayed by 10 seconds, starting 10 seconds after the page loads.

html
<!DOCTYPE html>
<html>

<head>
    <title>
        CSS animation-delay Property
    </title>
    <style>
        .geeks {
            font-size: 40px;
            text-align: center;
            font-weight: bold;
            color: #090;
            padding-bottom: 5px;
            font-family: Times New Roman;
        }

        .geeks1 {
            font-size: 17px;
            font-weight: bold;
            text-align: center;
            font-family: Times New Roman;
        }

        #one {
            animation-name: example;
            animation-duration: 10s;

        }

        #two {
            animation-name: example;
            animation-duration: 10s;
            animation-delay: 10s;
        }

        @keyframes example {
            from {
                background-color: orange;
            }

            to {
                background-color: white;
            }
        }
    </style>
</head>

<body>
    <div class="geeks">
        GeeksforGeeks
    </div>

    <div class="geeks1">
        A computer science portal for geeks
    </div>

    <!-- Animation of below h2 tag is not delayed
            and begins as soon as the page is loaded
            in the browser -->
    <h2 id="one">
        Text animation without delayed.
    </h2>

    <!-- The animation of below h2 tag is delayed for 10s
            That is, it begins after 10s of successfully
            loading of the current page -->
    <h2 id="two">
        Text animation with 10 second delay.
    </h2>
</body>

</html>

Output: 

Animation-delay-4
CSS animation-delay Property Example Output

Supported Browser

The browser supported by animation-delay are listed below:


Next Article

Similar Reads