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.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources