Add CSS transition effect for both the width and height property


To add transition effect for width and height property of an element, you can try to run the following code

Example

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            width: 150px;
            height: 150px;
            background: blue;
            transition: width 3s;
         }
         div:hover {
            width: 250px;
            height: 250px;
         }
      </style>
   </head>
   <body>
      <h1>Heading One</h1>
      <p>Hover over the below box to change its width and height.</p>
      <div></div>
   </body>
</html>

Updated on: 23-Jun-2020

469 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements