src

Published Jun 13, 2023
Contribute to Docs

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:

<video
source
controls
width="200"
src="https://youtu.be/0QHaxrUkSE"
type="youtube"
></video>

All contributors

Looking to contribute?

Learn HTML on Codecademy