Problem Statement
What does the src attribute in an img tag specify?
Explanation
The src attribute, which stands for source, specifies the path or URL to the image file that should be displayed. This is a required attribute for the img tag. The src can be a relative path like images slash photo dot jpg, which looks for the image relative to the current page location. It can also be a root-relative path like slash images slash photo dot jpg, which starts from the website root. Or it can be an absolute URL like https colon slash slash example dot com slash image dot jpg, which is the full web address. If the src path is incorrect or the image file does not exist, the browser will display a broken image icon. The src attribute is crucial because it tells the browser which image file to load and display on the page.
Code Solution
SolutionRead Only
<!-- Relative path --> <img src="photo.jpg" alt="Photo"> <!-- Folder path --> <img src="images/logo.png" alt="Logo"> <!-- Root-relative path --> <img src="/assets/banner.jpg" alt="Banner"> <!-- Absolute URL --> <img src="https://example.com/image.jpg" alt="External Image">
