Open In App
Related Articles

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

Improve Article
Improve
Save Article
Save
Like Article
Like

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




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


Last Updated : 14 Sep, 2020
Like Article
Save Article
Similar Reads
Related Tutorials