How to set the width and height of an image using HTML ?

The height and width of an image can be set using height and width attribute. The height and width can be set in terms of pixels.

The <img> height attribute is used to set the height of the image in pixels. The <img> width attribute is used to set the width of the image in pixels.

Example 1: In this example, we will set the width and height of an image.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
  
<head
    <title
        How to specify the width and 
        height of an image using HTML?
    </title
</head
  
<body
    <h1 style="color:green;">GeeksforGeeks</h1
  
    <h2>
        How to specify the width and 
        height of an image using HTML?
    </h2
  
    <img src
        alt="GeeksforGeeks logo" width="300" height="300"
</body
  
</html>

chevron_right


Output:



Example 2: In this example, we will not assign width and height value so the image will display with its original height and width.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
  
<head
    <title
        How to specify the width and 
        height of an image using HTML?
    </title
</head
  
<body
    <h1 style="color:green;">GeeksforGeeks</h1
  
    <h2>
        How to specify the width and 
        height of an image using HTML?
    </h2
  
    <img src
        alt="GeeksforGeeks logo" width="" height=""
</body
  
</html>

chevron_right


Output:

full-stack-img




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.