Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

HTML src Attribute


Definition and Usage

The src attribute specifies the location (URL) of the external resource.


Applies to

The src attribute can be used on the following elements:

Elements Attribute
<audio> src
<embed> src
<iframe> src
<img> src
<input> src
<script> src
<source> src
<track> src
<video> src

Examples

Audio Example

An audio player:

<audio src="horse.ogg" controls>
Your browser does not support the audio element.
</audio>
Try it Yourself »

Embed Example

An embedded flash animation:

<embed src="helloworld.swf">
Try it Yourself »

Iframe Example

An <iframe> in its simplest use:

<iframe src="/default.asp"></iframe>
Try it Yourself »

Img Example

An image is marked up as follows:

<img src="smiley.gif" alt="Smiley face">
Try it Yourself »

Input Example

An HTML form with an image that represents the submit button:

<form action="/action_page.php">
  First name: <input type="text" name="fname"><br>
  <input type="image" src="submit.gif" alt="Submit">
</form>
Try it Yourself »

Script Example

Point to an external JavaScript file:

<script src="myscripts.js"></script>
Try it Yourself »

Source Example

An audio player with two source files. The browser should choose which file (if any) it has support for:

<audio controls>
  <source src="horse.ogg" type="audio/ogg">
  <source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Try it Yourself »

Track Example

A video with two subtitle tracks:

<video width="320" height="240" controls>
  <source src="forrest_gump.mp4" type="video/mp4">
  <source src="forrest_gump.ogg" type="video/ogg">
  <track src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English">
  <track src="subtitles_no.vtt" kind="subtitles" srclang="no" label="Norwegian">
</video>

Video Example

Play a video:

<video src="movie.ogg" controls>
  Your browser does not support the video tag.
</video>
Try it Yourself »

Browser Support

The src attribute has the following browser support for each element:

Element
audio 4.0 9.0 3.5 4.0 10.5
embed Yes Yes Yes Yes Yes
iframe Yes Yes Yes Yes Yes
img Yes Yes Yes Yes Yes
input 1.0 2.0 1.0 1.0 1.0
script Yes Yes Yes Yes Yes
source 4.0 9.0 3.5 4.0 10.5
track 18.0 10.0 31.0 6.0 15.0
video 4.0 9.0 3.5 4.0 10.5

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.