Images are a great way to enhance a webpage. HTML uses the <img>
tag to display images. Since it’s a self-closing tag, it doesn’t need an end tag. You’ll specify the image location with the src
attribute, and an alt
attribute helps when images don’t load or for accessibility.
HTML Images Syntax
Explanation of Syntax:
<img>
: The image tag, used to embed an image.src="image_url"
: Thesrc
(source) attribute tells the browser where to find the image. This can be a URL or a file path.alt="Description of image"
: Thealt
(alternate text) attribute provides a text description of the image, useful for accessibility and as a fallback if the image doesn’t load.
HTML
x
<img src="image_url" alt="Description of image">
HTML Images Example Code
Explanation of Code:
src="https://www.example.com/image.jpg"
: Specifies the path to the image file. This can be a URL (like this example) or a local file.alt="Example Image"
: Thealt
text provides a description that is useful for screen readers and appears if the image fails to load. Here, it simply says “Example Image.”
HTML
<html>
<head>
<title>HTML Images Example</title>
</head>
<body>
<h1>HTML Image Example</h1>
<img src="https://www.example.com/image.jpg" alt="Example Image">
</body>
</html>