How to use image height and width attribute in HTML Page ?
HTML stands for HyperText Markup Language. Hypertext defines the link between the online pages. It is used to define the text document within tag which defines the structure of websites. This language is used to annotate text in order that a machine can know it and manipulate text accordingly. Most markup languages (e.g. HTML) are human-readable. The language uses tags to define what manipulation has got to be done on the text.
To add an image in an HTML page, <img> tag is used. With that, we need to use the attribute’s width and height of the image in pixels. Specify both of the attributes.
<img src="url" alt="some_text">
- src: The src stands for source. Every image has an src attribute which tells the browser where to find the image you want to display. The URL of the image provided points to the location where the image is stored.
- alt: If the image cannot be displayed then the alt attribute acts as an alternative description for the image. The value of the alt attribute is a user-defined text.
<img src="url" alt="some_text" width="" height="">
- px: pixels – pixels (1px = 1/96th of 1in)
- in: inches – inches (1in = 96px = 2.54cm)
- pt: points – points (1pt = 1/72 of 1in)
Example 1: An image with a height of 600 pixels and a width of 500 pixels. The width attribute specifies the width of a picture, in points.
Example 3: Another HTML program to show the use of <img> tag with width and height attribute. In this code, we have taken the value of height and width as 250 pixels.
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML course.