HTML <script> src Attribute
Definition and Usage
src
The attribute specifies the URL of the external script file.
If you want to run the same JavaScript on multiple pages of the website, you should create an external JavaScript file instead of writing the same script over and over again. 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.
Tip:Set src
The script element cannot contain content. You cannot use the same script element to define embedded scripts and to reference external scripts.
Tip:The script element that references an external script should be empty. If the script element is used as a self-closing tag to reference an external script, the browser will ignore this element and will not load the referenced file.
Syntax
<script src="URL">
Attribute Value
Value | Description |
---|---|
URL |
URL of the external script file. Possible Values:
|
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |