How to Resize Images in HTML: A Step-by-Step Guide

Gerald Jun 16, 2026

How to Change Image Size in HTML: A Step-by-Step Guide

Inserting and styling images in HTML 5.
Inserting and styling images in HTML 5.

Changing the size of an image in HTML is a simple yet crucial task for web developers and designers. Whether you want to optimize image loading times, adjust the layout of your webpage, or make your images more accessible, understanding how to modify image sizes is essential. In this article, we will walk you through the process of changing image size in HTML, covering the various methods and best practices to ensure you achieve the desired outcome.

How To Set The WordPress Featured Image Size
How To Set The WordPress Featured Image Size

Method 1: Using the Width and Height Attributes

One of the most straightforward ways to change image size in HTML is by utilizing the width and height attributes within the img tag. These attributes allow you to specify the width and height of the image in pixels. Here's an example:

Auto Resize Images In HTML CSS
Auto Resize Images In HTML CSS


This code will set the width of the image to 500 pixels and the height to 400 pixels. However, be cautious when using these attributes as they can affect the image's aspect ratio. Make sure to adjust both the width and height attributes in proportion to avoid distortion.

Method 2: Using CSS

How to Resize an Image Without Losing Quality
How to Resize an Image Without Losing Quality

CSS (Cascading Style Sheets) offers a more flexible and efficient way to change image size in HTML. By utilizing the width and height properties, you can easily modify the image's dimensions without affecting its aspect ratio. Here's an example:



Image description

In this example, the width of the image is set to 50% of its parent element, while the height is set to auto to maintain the original aspect ratio. This method is more versatile than the width and height attributes, as it allows for easier adjustments and responsiveness.

Method 3: Using the Max-Width and Max-Height Attributes

How to Reduce Image Sizes for WordPress, Social Media, E-Mail & More!
How to Reduce Image Sizes for WordPress, Social Media, E-Mail & More!

When working with responsive designs, it's essential to use the max-width and max-height attributes to ensure images scale correctly. These attributes allow you to specify the maximum width and height of the image, preventing it from exceeding those values while maintaining its original aspect ratio.


This code sets the maximum width of the image to 500 pixels and the maximum height to 400 pixels. This approach is particularly useful when dealing with images of varying sizes and aspect ratios.

Method 4: Using JavaScript

the three ways to apply css in html and wordpress, including an info sheet
the three ways to apply css in html and wordpress, including an info sheet

In some cases, you may need to dynamically change the image size based on user interactions or other conditions. JavaScript can be used to achieve this by manipulating the image's width and height properties directly.

Image description


This code sets the width of the image to 500 pixels using JavaScript, while the height is set to auto to maintain the original aspect ratio. Be aware that using JavaScript to change image size can have performance implications, especially when dealing with large images.

Auto Resize Image To Fit In HTML CSS
Auto Resize Image To Fit In HTML CSS
4 Ways To Keep Image Aspect Ratio In HTML CSS
4 Ways To Keep Image Aspect Ratio In HTML CSS
Learn Basic HTML & CSS: Change the Design of Your WordPress Blog | Studio 73 Designs
Learn Basic HTML & CSS: Change the Design of Your WordPress Blog | Studio 73 Designs
Embedding Images in HTML using <img>
Embedding Images in HTML using <img>
3 Ways To Place Text Over Image In HTML CSS
3 Ways To Place Text Over Image In HTML CSS
How to change image and PDF display sizes in Preview for Mac
How to change image and PDF display sizes in Preview for Mac
Very Simple HTML CSS Image Gallery
Very Simple HTML CSS Image Gallery
HTML Cheat Sheet 📄✨ Quick Guide for Beginners
HTML Cheat Sheet 📄✨ Quick Guide for Beginners
an image with the text how to place text over image in html css
an image with the text how to place text over image in html css
Resize Image In Javascript
Resize Image In Javascript
Mastering CSS Background Images
Mastering CSS Background Images
Change image shape with clip-path | HTML, CSS, JavaScript [no SVGs]
Change image shape with clip-path | HTML, CSS, JavaScript [no SVGs]
Simple Image Slider In HTML CSS
Simple Image Slider In HTML CSS
an image with the text, click box for more information and then clickbox for more information
an image with the text, click box for more information and then clickbox for more information
Fix Spacing in HTML with &nbsp; 🚀
Fix Spacing in HTML with &nbsp; 🚀
Create Rounded Images In HTML CSS
Create Rounded Images In HTML CSS
Download Canvas As Image In Javascript
Download Canvas As Image In Javascript
🔗 Overview of Adding Links and Images in HTML
🔗 Overview of Adding Links and Images in HTML
Cycle Completed! Prime Python, Java, JS Services: Loop Closed – Order for Infinite Innovations!
Cycle Completed! Prime Python, Java, JS Services: Loop Closed – Order for Infinite Innovations!
How to Change Canva Design Size – Step-by-Step
How to Change Canva Design Size – Step-by-Step

Best Practices and Considerations

  • Always maintain the original aspect ratio when resizing images to prevent distortion.
  • Use CSS whenever possible, as it offers more flexibility and is generally easier to maintain.
  • Be mindful of performance when using JavaScript to change image size, especially with large images.
  • Optimize image sizes for web use to reduce loading times and improve user experience.
  • Consider using lazy loading or image loading libraries to further improve performance.

Conclusion

Changing image size in HTML is a fundamental skill for web developers and designers. By understanding the various methods and best practices outlined in this article, you can effectively adjust image sizes to achieve your desired outcome. Whether you're working with responsive designs, optimizing image loading times, or making your images more accessible, mastering image size manipulation is essential for creating high-quality web experiences.