Skip to content
Related Articles

Related Articles

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

Improve Article
Save Article
  • Last Updated : 14 Sep, 2020
Improve Article
Save Article

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:


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!