This article will show you how to set the height and width of an image in HTML.
- The "width" attribute sets the width of the picture (in pixels).
- The "height" attribute sets the height of the image (in pixels).
- In HTML4.01, the height can be set in pixels or as a percentage, but in HTML5, only in pixels.
Steps

Step 1. Open the file with HTML code
For example, open the file default.html.

Step 2. Add the following line to your HTML code
-
- v
src
the path to the graphic file (picture) is indicated. - v
alt
the size of the picture is set.

Step 3. Replace the attribute values
height
and
width
on the right ones.
For example, like this:
height = "19"

Step 4. Save the file and open it in any web browser
Do this to check how the image is resized. The "width" attribute is supported by all major browsers (Google Chrome, Safari, Mozilla Firefox, Opera, Internet Explorer).
Advice
- Always set the height and width of the picture. So when the page is loaded, space is reserved for the picture. Otherwise, the browser will not know the size of the image and will not reserve space, causing the page layout to change as the page loads.
- If the size of a large image is reduced using the "height" and "width" attributes, the user will load the large image (even if it appears small on the page). Therefore, we recommend that you first resize the image in a graphics editor.