Open In App

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. 

Syntax

object.style.transition
object.style.transition = "property duration timing-function delay | initial | inherit"

Return Values

It returns a string that represents the transition property of an element.

Property Values

ValueDescription
transitionPropertyName of CSS property for transition effect.
transitionDurationHow much time is taken to complete the transition
transitionTimingFunctionSpeed of transition
transitionDelayStarting point of transition
initialSet to default value
inheritInherit from its parent element

Example: In this example, we are creating a div tag whose CSS is defined in style tag and when you hover the mouse on div tag after clicking on submit button the CSS will change from myDIV CSS to myDIV: hover CSS. 

<!DOCTYPE html>
<html>

<head>
    <title>
        HTML DOM Style transition Property
    </title>

    <style>
        body {
            text-align: center;
        }
        #container {
            border: 1px solid black;
            border-radius: 5px;
            background-color: #e1e1e1;
            width: 200px;
            height: 100px;
            margin: auto;
            margin-bottom: 20px;
        }

        #container:hover {
            background-color: #228B22;
            width: 400px;
        }
    </style>
</head>

<body>
    <h2>HTML DOM Style transition Property</h2>

    <div id="container"></div>

    <button onclick="myFunction()">
        Click Here!
    </button>
    
    <script>
        function myFunction() {
            document.getElementById("container").style.WebkitTransition = "width 3s";

            document.getElementById("container").style.transition = "width 3s";
        }
    </script>
</body>

</html>

Output:

HTML-DOM-Style-transition-Property

Note: The transitionDuration can be only non-negative number and it can't be zero otherwise the transaction effect will not shown. Instead of all we can use following CSS properties:

Supported Browsers

Article Tags :