English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The src attribute specifies the URL of an external script file. If the same JavaScript needs to be run on multiple pages of a website, it is better to create an external JavaScript file rather than writing the same script over and over again. Save the script file with the .js extension and then refer to it using the src attribute of the <script> tag.
src points to an external JavaScript file:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>HTML: Usage of the src Attribute in <script>-Basic Tutorial(oldtoolbag.com)</title> </head> <body> <script src="demo_script.js"></script> </body> </html>Test and see ‹/›
IEFirefoxOperaChromeSafari
All major browsers support the src attribute.
The src attribute specifies the URL of the 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 over and over. 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: The exact location of the external script file is where you write your script.
None.
<script src="URL">
Value | Description |
---|---|
URL | URL to link an external script file. Possible values:
|