How to adjust CSS for specific zoom level?

In this article, we are going to learn how do we adjust the CSS for a specific zoom level. The CSS zoom property allows scaling of the content. This property is not recommended for production sites because it doesn’t support in some browsers.

Values:

  • percentage: Scaling by percentage
  • number: Scaling using percentage, e.g 1 = 100% and 1.5 = 150%
  • normal: zoom: 1

Syntax: (The zoom here is set at 100%. Change it accordingly.)

<button onclick="sampleDiv.style.zoom='100%'">Zoom 100%</button>

Example: This example shows how to adjust CSS for specific zoom level.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        adjust CSS for specific zoom level
    </title>
</head>
  
<body style="text-align:center">
    <h2 style="color:green">
      GeeksForGeeks
  </h2>
    <h2 style="color:purple">
      adjust CSS for specific zoom level
      </h2>
    <div id="sampleDiv" style="width: 100px; background-color: green; ">
        <img src=
             alt="Trulli" 
             width="250" 
             height="250"
             align="middle"
             class="center">
    </div>
    <button onclick="sampleDiv.style.zoom='100%'">
      Zoom 100%
  </button>
    <button onclick="sampleDiv.style.zoom='50%'">
      Zoom 50%
  </button>
    <button onclick="sampleDiv.style.zoom='200%'">
      Zoom 200%
  </button>
</body>
  
</html>

chevron_right


Output:

Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Apple Safari
  • Opera


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.