HTML Script src attribute


Link to an external script file:
<script type="text/javascript" src="myscripts.js"></script>

Definition and Usage

The src attribute specifies the URL of an external script file.
Sometimes you want to run the same JavaScript on several pages in a web site. Instead of writing the same script over and over again, create your JavaScript in a standalone file, save it with a .js extension, and then refer to it using the src attribute in the <script> tag.
Note: The external script file cannot contain the <script> tag!
Note: Remember to place the script exactly where you normally would write the script!

Browser Support

The src attribute is supported in all major browsers.


<script src="URL">

Attribute Values

Value Description
URL The URL of the external script.Possible values:
  • An absolute URL - points to another web site (like src="")
  • A relative URL - points to a file within a web site (like src="/scripts/example.js")
HTML Script src attribute Reviewed by 1000sourcecodes on 20:58 Rating: 5
Powered by Blogger.