HTML <script> srcAttribute

HTML script 标签参考手册HTML <script> Tag

Examples

Point to an external JavaScript file:

<script src="myscripts.js.html"></script>

Try it Yourself »

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the src attribute.


Definition and Usage

The src attribute specifies the URL of an external script file.

If you want to run the same JavaScript on multiple pages of your website, you should create an external JavaScript file instead of writing the same script repeatedly. Save the script file with a .js extension, and then reference it using the src attribute in the <script> tag.

Note:External script files cannot contain <script> tags.

Note:Correctly reference the external script file in which you write your script.


Differences between HTML 4.01 and HTML5

None.


Syntax

<script src="URL.html">

Attribute Values

Value Description
URL The URL of the external script file.

Possible values:

  • Absolute URL - points to another website (e.g., src="http://www.example.com/example.js")
  • Relative URL - points to a file within the website (e.g., src="../scripts/example.js.html")


HTML script 标签参考手册HTML <script> Tag Other Extensions