Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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

  • Last Updated : 14 Sep, 2020

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.

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

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

HTML




<!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>

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




<!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>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!