HTML src Attribute

HTML src Attribute: This attribute defines the URL of the external resource. And the <audio>, <embed>, <source>, <track> and <video>tags are not supported in HTML4. These are newly added in HTML5.

HTML src Attribute

This attribute can be applied on <audio>,<embed>,<iframe>,<img>,<input>,<script>,<source>,<track>, and <video> elements.

Syntax: <img src=”URL”>

Browser Support

This attribute is supported by the following browsers:

  • Chrome
  • Firefox
  • Safari
  • Opera
  • Internet Explorer

Example: for <embed> element

<!DOCTYPE html>
<html>
<body>
<embed src="helloworld.swf">
</body>
</html>

Output:

HTML src attribute

HTML src attribute

Example: for <iframe> element

<!DOCTYPE html>
<html>
<body>
<iframe src="https://tutorials.freshersnow.com/wp-content/uploads/2019/04/cropped-Tutorials-by-Freshersnow.png">
  <p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>

Output:

 

 

Example: for <img> element

<!DOCTYPE html>
<html>
<body>
<img src="smiley.gif" alt="Smiley face" width="42" height="42">
</body>
</html>

Output:

HTML img element

 

Example: for <input> element

<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
  First name: <input type="text" name="fname"><br>
  <input type="image" src="submit.gif" alt="Submit" width="48" height="48">
</form>
</body>
</html>

Output:

HTML src attribute

Example: for <script> element

<!DOCTYPE html>
<html>
<body>
<script src="demo_script_src.js">
</script>
</body>
</html>

Output:

This text comes from an external script.

Example: for <video> element

<!DOCTYPE html>
<html>
<body>
<video width="320" height="240" controls src="movie.ogg">
 </video>
</body>
</html>