The HTML <img> element is used to embed images in web pages. It is a self-closing tag, which means it doesn’t require a closing tag.
Use the HTML <img> element to define an image
The <img> element is used to embed images in HTML documents. It is an inline element, which means it is placed within a block of text and does not create a new line. Here’s an example:
1 2 3 |
<img src="the_image.jpg" alt="A beautiful sunrise"> |
This will display the image “the_image.jpg” with an alternate text “A beautiful sunrise”. The alt attribute is used to specify an alternate text for an image, which is displayed when the image cannot be displayed. This is useful for accessibility and SEO purposes. Here’s an example:
HTML width and height attributes
The width and height attributes are used to specify the size of the image in pixels.
1 2 3 |
<img src="the_image.jpg" alt="A beautiful sunrise" width="600" height="400"> |
This will display the image “the_image.jpg” with an alternate text “A beautiful sunrise” and a size of 600 pixels wide and 400 pixels high
HTML Images Summary
You can now use the <img> element and it’s attributes to embed images in your HTML documents..