<

HTML <script> Tag

The <script> tag is used to define a client-side script (JavaScript).The <script> element either contains scripting statements, or it points to an external script file through the src attribute.

Attributes



Attribute Value Description
async async Specifies that the script is executed asynchronously (only for external scripts)
charset charset Specifies the character encoding used in an external script file
defer defer Specifies that the script is executed when the page has finished parsing (only for external scripts)
src URL Specifies the URL of an external script file
type media_type Specifies the media type of the script
xml:space preserve Not supported in HTML5.
Specifies whether whitespace in code should be preserved


Example




<!DOCTYPE html>
<html>
<body>

<h2 id="h2"></h2>

<script>
document.getElementById("h2").innerHTML = "Hello World";
</script> 

</body>
</html>
















© copyright 2017-2022 Completedone pvt ltd.