Easy Tutorial
❮ Prop Style Bordercollapse Prop Embed Width ❯

Script src Attribute

Script Object

Example

Get the URL of an external script:

x Output result:


Definition and Usage

The src attribute sets or returns the value of the src attribute of a script.

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 repeating the same script. Save the script file with a .js extension and then reference it using the src attribute in the <script> tag.

Note: External script files should not contain <script> tags.

Note: Properly reference the external script file you have written.


Browser Support

All major browsers support the src attribute.


Syntax

Return the src attribute:

Set the src attribute:

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")<br> Relative URL - points to a file within the website (e.g., src="/scripts/example.js")

Technical Details

| Return Value: | String, representing the URL of the external script file. Returns the full URL, including the protocol (e.g., http://). | | --- | --- |


Related Articles

HTML Reference: HTML <script> src Attribute


Script Object

❮ Prop Style Bordercollapse Prop Embed Width ❯