What does the 'src' attribute do in an <img> tag?

Study for the Code.org Computer Science Discoveries Test. Engage with flashcards and multiple choice questions, each with hints and explanations. Get prepared for your exam!

Multiple Choice

What does the 'src' attribute do in an <img> tag?

Explanation:
The main idea is that the src attribute tells the browser where to find the image file so it can display it on the page. It should point to a location such as a URL or a relative file path in your project. When the page loads, the browser uses that path to fetch the image and render it in place of the tag. If the path is wrong or the file isn’t there, you’ll see a broken image indicator or nothing at all. Other attributes handle different aspects: the alt text provides a description for accessibility and screen readers, while width and height adjust how big the image appears. Captions are added separately, not by the src attribute. For example, you might write <img src="images/photo.jpg" alt="A scenic view">.

The main idea is that the src attribute tells the browser where to find the image file so it can display it on the page. It should point to a location such as a URL or a relative file path in your project. When the page loads, the browser uses that path to fetch the image and render it in place of the tag. If the path is wrong or the file isn’t there, you’ll see a broken image indicator or nothing at all. Other attributes handle different aspects: the alt text provides a description for accessibility and screen readers, while width and height adjust how big the image appears. Captions are added separately, not by the src attribute. For example, you might write A scenic view.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy