The <script>
tag is used to add client-side scripts, like javascript in the document.
It can be defined anywhere within the webpage. The <script>
element either contains scripting statements, or it points to an external script file through the src
attribute.
Attributes | Description |
---|---|
src | It specifies the URL of an external script file. |
type | It specifies the type of the script. |
async | It specifies that the script will be executed asynchronously with the webpage. It should only be used with external scripts. |
defer | It is a boolean value which specify that the script is executed after document has been parsed completely. |
type
attribute was required in HTML 4 but it is optional in HTML 5. There is no need to define the type of the script in HTML 5.
Just like embedded css, the script tag can be used within <body>
or <head>
tag to directly write the javascript code within the webpage.
Have a look at the example below :
The <script>
tag can also be used to link an external script file by using src
attribute. It is recommended to be used within the <head>
tag only.
The external script is very useful when we have to use same script in more than one page. The script can be written in an external file, and then it can be added in any webpage where it is required.
The The <noscript>
tag is used to provide an alternate content for users which have javascript disabled in their browser or if their browser doesn't support scripts.Look at the example to know more :
Follow Us: