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>