What are the height/width attributes in HTML?

Overview

In HTML, the height and width attributes are used to set the height and width of an element. We can define the height and width values in terms of pixels.

We can set the height of the image by using the <img> height attribute and width by using the <img> width attribute.

Example

The basic HTML code to demonstrate the use of the height/width attribute is as follows:

  • HTML
Using the "width" and "height" tag

Explanation

In this example, we can see that we set the height and width of the image. We can also set the height and width according to our own choice.