src
The 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.
Syntax
<element src="url">
src
can also be used in the following elements:
HTML Tag | Description |
---|---|
<audio> |
Embeds sound files on websites and applications. |
<img> |
Embeds online photos, logos, and other pictures into an HTML file. |
<input> |
Creates interactive textboxes for online forms. |
<script> |
Embeds JavaScript and other executive code or data into an HTML file. |
<track> |
Specifies the subtitles and closed captions for <audio> and <video> elements. |
<video> |
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
alt
text 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:
<videosourcecontrolswidth="200"src="https://youtu.be/0QHaxrUkSE"type="youtube"></video>
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.