HTML

HTML provides the <script> tag in order to put different scripts inside the HTML. The <script> is generally used for JavaScript but can be also used for other scripting languages. The <script> generally contains scripting statements, functions, variables etc.

<script> Tag Attributes

Event the <script> tag is mostly related to the scripts it provides some attributes to set script features. For example async attribute is used to download the specified script file asynchronously which makes the page load faster.

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-credentials
Sets 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
nomoduleTrue
False
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-url
Specifies which referrer information to send when fetching a script
srcURLSpecifies the URL of an external script file
typescripttypeSpecifies the media type of the script

<script> Tag Example

The Javascript scripts can be put inside the <script> tags. The <script> tag is used to set the start of the script. The </script> tag is used to express the end of the script. All content between <script> and </script> are interpreted as script and treated different than HTML tags. The type attribute is used to specify the script type. In the following example we set the type attribute as text/JavaScript .

<html>

   <head>
      <title>Script Tag Example</title>
   </head>

   <body>
      <script type = "text/JavaScript">
         document.write("You're visiting wisetut!")
      </script>
   </body>
	
</html>

Download Script As File

Another usage for the <script> tag is specifying the script file location by using the src attribute. In the following example we load the script from the www.wisetut.com .

<html>

   <head>
      <title>Script Tag Example</title>
   </head>

   <body>
      <script type = "text/JavaScript" src="https://www.wisetut.com/main.js">
   </body>
	
</html>

Leave a Comment