Script Tag in HTML5
In this article I am going to describe about the implementation and use of Script Tag in HTML5.
Script Tag
The <script> tag is most important for dynamic page. It is use for adding capability of scripting language in HTML document. We also use <noscript> tag for providing content to browsers that don't support your scripting language.
The <script> tag is used to define a client-side script, such as a JavaScript. The <script> element either contains scripting statements, or it points to an external script file through the src attribute.Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.
The HTML script
element is used to embed or reference an executable script within an HTML or XHTML document. Scripts without async
or defer
attributes are fetched and executed immediately, before the browser continues to parse the page.
Browser Support
<script> tag is supported in all major browsers.
Syntax
Syntax of <script> Tag in HTML5
<script type="">Scripting code</script>
Attributes
Attributes |
Value |
Description |
async |
async |
Specifies that the script is executed asynchronously |
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(loaded) |
src |
src |
Specifies the URL of the external script file |
type |
mime-type |
Specifies the type of script. |
Example
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Script Tag</title>
</head>
<body>
<h1>Implementation of <script> tag in HTML5.</h1>
<script>
document.write("This tag is used to define a client-side script, such as a JavaScript.")
</script>
</body>
</html>
Output