How to use height and width attributes in HTML?


The height and width attribute in HTML is used to specify the height and width of the element. The values are set in px i.e. pixels.

The height and width attribute is used in the following HTML elements:

S. No
Elements
Attribute
Attribute
1
<canvas> element
height
width
2
<embed> element
height
width
3
<iframe> element
height
width
4
<img> element
height
width
5
<input> element
height
width
6
<object> element
height
width
7
<video> element
height
width

To add an image in an HTML page, <img> tag is used. With that, we need to use the attributes height and width to set the height and width of the image in pixels.


Example

You can try to run the following code to learn how to use height and width attributes in HTML.

<!DOCTYPE html>
<html>
   <head>
      <title>HTML height and width attribute</title>
   </head>
   <body>
      <img src="https://www.tutorialspoint.com/green/images/logo.png" alt="Simply Easy Learning" width="200" height="70">
   </body>
</html>

Updated on: 14-May-2020

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements