src attribute is used to specify the location of a digital source, which is typically a URL. It is required for HTML elements like
<img> so that they can appear on a website or application.
src can also be used in the following elements:
||Embeds sound files on websites and applications.|
||Embeds online photos, logos, and other pictures into an HTML file.|
||Creates interactive textboxes for online forms.|
||Specifies the subtitles and closed captions for
||Embeds movie clips or other video sources into an HTML file.|
Example 1: Image
The snippet below shows a logo being inserted into an HTML file:
<img src="logo.png" alt="Codecademy logo" />
Note: When using online images or images from the folders in an IDE workspace, always add
alttext at the end of the
<img>element just in case the browser has trouble finding them.
Example 2: Video
The snippet below shows a video being inserted into an HTML file: