All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

CSS Zoom Background Image On Hover

Last Updated : Mar 11, 2024

CSS Zoom Background Image On Hover

In this article we will show you the solution of css zoom background image on hover, the Cascading style sheet or CSS is used to add style to the HTML. In this tutorial, we will see how a background image zooms while hovering over them using the mouse.

The background image zooms on hover can be done with a pseudo-class :hover. We’re going to use the CSS transform property in this tutorial.

Step By Step Guide On CSS Zoom Background Image On Hover :-

Let us see an example of a CSS zoom background image on hover.

<!DOCTYPE html>
<html lang = " en " >
<head>
    <meta charset = " UTF - 8" >
    <meta http-equiv = " X-UA-Compatible " content = " IE=edge " >
    <meta name = " viewport " content = " width = device-width , initial-scale = 1.0 " >
    <title> CSS zoom background image on hover </title>
    <style>
        h1 {
         font-size : larger ;
         font-weight : bolder ;
         color : lightgreen ;
        }
        .div{
            height: 600px;
            width: 600px;
            overflow: hidden;
        }
        .image {
            height : 100%;
            width : 100%;
            background-size: cover;
            background-position: center;
        }
        .image:hover {
            transform: scale(2.0);
        }
        </style>
</head>
<body>
    <h1> TALKERSCODE </h1>
   <p> CSS zoom background image on hover </p>
    <div class="div">
        <div class="image">
    <img src = " https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg " alt = " " >
   </div>
</div>
</body>
</html>
  1. First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
  2. Secondly, the <html> tag is used to indicate the beginning of an HTML document.
  3. As above now the <head> tag is used to contain information about the web page. In this tag, a <title> tag is used which helps us to specify a webpage title.
  4. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
  5. Thirdly, the <body> tag is used to define the webpage body. All the contents to show on the website are written here.
  6. <h1> tag used to add heading here.
  7. Creating a <div> with a class “ div ” .
  8. Within that <div>, Create a <div> with the class “ image ” tag that contains an image URL.
  9. Now create the <style> tag between the <head> tag
  10. Addressing the class “ div ”, add the “ height ” and the “ weight ” property. We’re also setting the “ overflow “ property hidden to hide the overflow.
  11. Now addressing the class “ image “ , set the “ height ” and the “ weight ” property to 100%. Also setting the “ background-size “ to cover and the “ background-position “ to center.
  12. Again Address the class “ image “ with the pseudo-class :hover , adding the “ transform ” property by the scale( ). By changing the scale you can zoom as much as you can.

Conclusion :-

At last here in conclusion, here we can say that with the help of this article we are able to give CSS zoom background image on hover.

I hope this article on css zoom background image on hover helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Pragati

Experienced coding content writer who enjoys breaking down complex concepts in programming languages like Java, Python, C, and C++. Over three years of experience producing interesting and relevant content for a variety of entities. Committed to providing concise and easy-to-understand articles that assist readers in easily understanding technology and industry trends in the world of coding and software development.

Follow Pragati On Linkedin 🡪