Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

HTML Script Tag


HTML script tag is used to specify client-side script such as JavaScript. It facilitate you to place a script within your HTML document.

JavaScript is used for image manipulation, form validation, and dynamic content.

The syntax of script tag is given below:

  1. <script>
  2.   //code to be executed
  3. </script>

Attributes of HTML script tag

Attribute Description Compatibility
src It specifies the URL of an external script file. HTML 4.01, HTML5
type It specifies the media type of the script. HTML 4.01
async It is a boolean value which specifies that the script is executed asynchronously. HTML5
defer It is a boolean value which is used to indicate that script is executed after document has been parsed. HTML 4.01, HTML5

Usage of script tag

There can be two usage of HTML script tag:

  1. to embed script code
  2. to link script file

Embed script code

The script tag can be used within <body> or <head> tag to embed the scripting code. Let’s see the example to have script tag within HTML body.

  1. <script type=“text/javascript”>
  2. document.write(“JavaScript is a simple language for Kreationnext learners”)
  3. </script>

Test it Now

Output:

JavaScript is a simple language for Kreationnext learners


Let’s see the example to have script tag within HTML head tag.

  1. <script type=“text/javascript”>
  2. function msg(){
  3.  alert(“Hello Kreationnext”);
  4. }
  5. </script>

Test it Now


Link script file

The script tag can be used to link external script file by src attribute. It must be used within the <head> tag only.

  1. <script type=“text/javascript” src=“message.js” />

Click me to see full example


Supporting Browsers

Element chrome_browser Chrome ie_browser IE firefox_browser Firefox opera_browser Opera safari_browser Safari
<script> Yes Yes Yes Yes Yes

Comments

comments