Computer >> Computer tutorials >  >> Programming >> CSS

How to zoom/scale an element on hover with CSS?


To zoom/scale an element on hover with CSS, the code is as follows −

Example

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
   * {
      box-sizing: border-box;
   }
   .zoomDiv {
      padding: 50px;
      background-color: yellow;
      transition: transform 0.2s;
      width: 200px;
      height: 200px;
      margin: 70px;
      border-radius: 50%;
      border: 4px solid rgb(78, 37, 155);
   }
   .zoomDiv:hover {
      transform: scale(1.5);
   }
</style>
</head>
<body>
<h1>Zoom on Hover Example</h1>
<h2>Hover over the below element to see it zoom.</h2>
<div class="zoomDiv"></div>
</body>
</html>

Output

The above code will produce the following output −

How to zoom/scale an element on hover with CSS?

On hovering over the yellow circle −

How to zoom/scale an element on hover with CSS?