The src attribute specifies the URL of the page to embed.
If the src attribute is not specified, nothing will be displayed on the page.
The src attribute can be used on the following elements:
The location of the external file can come in two ways:
- The first one is the local file that you saved on the computer, and you can access it by writing the file directory as
- The second one is the online file that you get from the internet, and you can access it by writing the URL as
An example code
Here are some examples of how to use the
src attribute in an HTML file.
An image source file:
<img src="./Rick Astley - Never Gonna Give You Up.png" alt="Rick Astley" />
A video source file:
<video controls> <source src="./Rick Astley - Never Gonna Give You Up.webm" type="video/webm"/> </video>
An audio source file:
<audio controls> <source src="./Rick Astley - Never Gonna Give You Up.mp3" type="audio/mp3" /> </audio>
Notice about src attribute
src attribute is usually used in
audio, it also supports other elements like