asp.net.ph

Skip Navigation LinksHome > Abakada: Back to Basics > Language References > HTML Elements > SCRIPT Element

<SCRIPT Element | SCRIPT Object


Specifies a script to run for the page.HTML 4, 4.01, 5

HTML Syntax

Remarks

A script is a type of computer code, or a set of instructions that can directly be executed by a program that understands the language in which the script is written, such as the Web browser.

The SCRIPT element specifies client-side script code, or specifically ECMA-standard JavaScript code that can be run directly in the browser, and is inserted directly into the HTML page.

Although SCRIPT elements can in theory be placed anywhere in the HTML page, functions in the SCRIPT element that will need user interaction must be placed in the HEAD of the document, as then the functions will be available to the document as it is loaded.

SCRIPT to be executed in a certain part of the document must be inserted in the appropriate place in the document BODY where the code will act upon.

Code within the SCRIPT block that is not contained within a function is executed immediately as the page is loaded.

The SCRIPT element can also be used to insert and run code from an external JavaScript file, using the src attribute.

To keep scripts from being displayed on down-level browsers, the SCRIPT block should be nested within a COMMENT block.

The NOSCRIPT element can be used to provide content that is displayed by browsers for which JavaScript is not available, while being ignored by browsers that can understand JavaScript. For example, authors can use NOSCRIPT to provide a warning that the page requires JavaScript.

A SCRIPT element appearing after a FRAMESET element is ignored.

Please see the chapter on Basic Scripting for detailed information on how JavaScript can be used to enhance Web pages.

NOTE: Both start and end tags are required.

Attributes

The <script> element supports the following attributes, in addition to global attributes common to all HTML elements.

AttributeValueDescription
asyncasyncSpecifies that the script is downloaded in parallel to parsing the page, and executed as soon as it is available (before parsing completes) (only for external scripts)
crossoriginanonymous, use-credentialsSets the mode of the request to an HTTP CORS Request
deferdeferSpecifies that the script is downloaded in parallel to parsing the page, and executed after the page has finished parsing (only for external scripts)
integrityfilehashAllows a browser to check the fetched script to ensure that the code is never loaded if the source has been manipulated
nomodule Specifies that the script should not be executed in browsers supporting ES2015 modules
referrerpolicyno-referrer, no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-urlSpecifies which referrer information to send when fetching a script
srcURLSpecifies the URL of an external script file
typescripttypeSpecifies the media type of the script
See Also

Implementing JavaScript in HTML



Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note