HTML script tag

HTML <script> tag adds the script in the html document. Script can be added directly in between the elements (inline) or imported from an external source using src attribute.

Example

<p>script element is used to add javascript in a page. For example, we make a function of cube in javascript.</p>	
<script>
 var x=5;
 function product(x){
 document.write(x*x*x);
 }
 product(5);
</script>
Try </>

Specific Uses

It makes the content dynamic.

Tip: The script should be placed at the end of a page.

Global Attributes

All the global attributes are applicable on the script element.

Tag omission

Both opening and closing tags are necessary for the script element.

Specific Attributes

AttributesDescription
src Address of the file to be imported.
<script src="address of the file to be improted"> </script>
type Specifies the type of language of the script.
<script src="address" type="text/javascript"> ...... </script>
crossorigin describes about the crossorigin requests.
<script crossorigin="anonymous"> ..... </script>
charset describes about the crossorigin requests.
<script charaset="UTF-8"> ..... </script>


Was this article helpful?

 

Email:

Message:

Get the newsletter