HTML
CSS
JS
Result
HTML
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Zoom an image on mouse hover by using CSS transform and scale property </title> </head> <body> <div class="img-div"> <img src="https://www.w3coderschool.com/attachments/file_1729864290.png" alt="w3coderschool Image" /> </div> </body> </html>
CSS
.img-div { margin: 0 auto; width: 300px; height: 300px; overflow: hidden; } .img-div img { width: 100%; transition: 0.5s all ease-in-out; } .img-div:hover img { transform: scale(1.5); }
JS
Zoom an image on mouse hover by using CSS transform and scale property