src attribute
The src attribute in <img> tag specifies the image’s location. If the URL is correct, the browser retrieves and displays the image; otherwise, it shows a broken link icon.
Example : In this example we displays an image using the <img> tag with src attribute pointing to a w3wiki logo. It enhances content by visually representing the website’s identity.
<!DOCTYPE html>
<html>
<head>
<title>Welcome To GFG</title>
</head>
<body>
<h2>w3wiki</h2>
<p>This is the demo of <img /> tag.</p>
<img src=
"https://media.w3wiki.org/wp-content/uploads/20210915115837/gfg3-300x300.png"
alt="GFG image" />
</body>
</html>
Output:
HTML Images
The HTML <img> tag is used to embed an image in web pages by linking them. It creates a placeholder for the image, defined by attributes like src, width, height, and alt, and does not require a closing tag.
There are 2 ways to insert the images into a webpage:
- By providing a full path or address (URL) to access an internet file.
- By providing the file path relative to the location of the current web page file.
We will first discuss inserting the image into the webpage & simultaneously, we will understand both the above approaches.