Latest web development tutorials

HTML script src attribute

HTML script tags reference manual HTML <script> tag

Examples

Refers to an external JavaScript file:

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

try it"

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the src attribute.


Definition and Usage

src attribute specifies the URL of an external script file.

If you want to run the same JavaScript on the site of several pages, you should create an external JavaScript file, instead of repeating the same scripting. The extension .js script file to be saved, and then refer to it using the src attribute in <script> tag.

Note: The external script file can not contain <script> tag.

Note: The script is written correctly reference your external script file.


Differences between HTML 4.01 and HTML5

no.


grammar

<script src="URL">

Property Value

描述
URL 外部脚本文件的 URL。

可能的值:

  • 绝对 URL - 指向另一个网站(比如 src="http://www.example.com/example.js")
  • 相对 URL - 指向网站内的一个文件(比如 src="/scripts/example.js")


HTML script tags reference manual HTML <script> tag