19 Aug Image height and width attribute in HTML
Let’s say you are developing a website and want to add an image. For this, the <image> tag is used. But, what about the height and width of the image, which is necessary to be set while adding an image on a web page.
To add height and with of an image, use the height and width attribute, respectively in the <img> tag. Let’s say we have an image with the following link:
1 2 3 |
https://studyopedia.com/wp-content/uploads/2017/02/Studyopedia-Quizzes.png |
Now, to add it on the web page, use the <img> tag. Set the height and width attributes as well:
1 2 3 |
<img src="https://studyopedia.com/wp-content/uploads/2017/02/Studyopedia-Quizzes.png" alt="Quiz" width="600" height="400"> |
Remember, the height and wisth of an image is set in pixels. Therefore, we have set the height and width as 400 pixels and 600 pixels respectively.
Example
Let us now see an example to set an image with height and width on a web page:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<!DOCTYPE html> <html> <head> <title>HTML Document</title> </head> <body> <h1>Attempt Programming Quiz</h1> <p>Test your knowledge with the following quizzes:</p> <img src="https://studyopedia.com/wp-content/uploads/2017/02/Studyopedia-Quizzes.png" alt="Quiz" width="600" height="400"> </body> </html> |
No Comments