Resizing an image using jQuery is easily done by using the css() method. We can target the width and height properties using the css() method and use that to resize our image.
$("#image").css("width","50%");
Let’s say we have the following HTML:
If we want to resize the image to be a set width and height, we can use the jQuery css() method in the following jQuery code.
$("#div1 img").css("width","150px");
$("#div1 img").css("height","150px");
If you are using WordPress, don’t forget to change the $ to jQuery as below:
jQuery("#div1 img").css("width","150px");
jQuery("#div1 img").css("height","150px");
Note this can also be done in pure JavaScript as well.
Using jQuery to Resize an Image with a Click
To resize an image using jQuery, we can combine the css() method with a click event.
In this example, we will have an image that we will want to resize. The image will be in a div that will have a width of 300px. The image will start at a width of 100% to fill the entire div.
We will have a button that will allow the user to resize the image to a new width each time they press it.
Here is our HTML code:
Resize image
We can utilize both the jQuery css() method and the jQuery click() method to resize the image.
We can then use the css() method to target the width and height properties and use it to resize our image.
In this example, when the user clicks to resize the image, we will generate a random number from 0-100, and then set the width to that percentage.
We will let the user see the new width of the image by populating the #result div with the new width percentage using the text() method.
Below is the JavaScript code which will allow the user to be able to resize our image by a random percentage each time:
$("#click-me").click(function(){
var random = Math.round(Math.random() * 100);
var newWidth = random + "%";
$("#div1 img").css("width", newWidth);
$("#result").text("width: " + newWidth);
});
The final code and output for this example on resizing an image in jQuery is below:
Code Output:

Full Code:
Resize image
Hopefully this article has been useful for you to understand how to use jQuery in resizing an image.