Cover Image for HTML img Tag
69 views

HTML img Tag

The <img> tag is an HTML element used to embed images in a web page. It is a self-closing tag, which means it doesn’t require a closing tag.

Here’s an example of how the <img> tag is used:

HTML<span role="button" tabindex="0" data-code="<!DOCTYPE html> <html> <head> <title>My Web Page</title> </head> <body> <h1>Welcome to My Web Page</h1> <img src="image.jpg" alt="Description of the image"> </body>
<!DOCTYPE html>
<html>
     <head>
          <title>My Web Page</title>
     </head>
     <body>
          <h1>Welcome to My Web Page</h1>
          <img src="image.jpg" alt="Description of the image">
     </body>
</html>

In this example, the <img> tag is used to display an image on the web page. The src attribute specifies the path or URL of the image file. The alt attribute provides alternative text that is displayed when the image cannot be loaded or for accessibility purposes.

Additionally, the <img> tag supports several other attributes to control the appearance and behavior of the image, such as width, height, border, align, and more. Here’s an example:

HTML<span role="button" tabindex="0" data-code=""Description
<img src="image.jpg" alt="Description of the image" width="300" height="200" border="1">

In this case, the image will have a width of 300 pixels, a height of 200 pixels, and a border of 1 pixel.

It’s important to ensure that the src attribute points to a valid image file or URL. Common image formats supported by browsers include JPEG, PNG, GIF, and SVG.

Remember to provide meaningful alternative text using the alt attribute for images. This helps with accessibility by providing text descriptions for users who cannot see the image or when the image fails to load.

You can also use CSS to style and position the <img> element on your web page.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS