The HTML <script> tag is used for declaring a script (such as JavaScript) within your HTML document.
Also see the <noscript> tag for providing content to browsers that don't support your scripting language.
Required Attributes
- type is used to specify what type of scripting language is used. This takes the form of a MIME type such as text/javascript.
Optional Attributes
- src can be used to specify an external source of a script file.
- charset can be used to specify the character set of the element.
- defer can be used to specify that the script does not generate any document content so that the browser doesn't have to worry about it while the page loads. It must be used in the format defer="defer".
Example
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript">
function lion() {
alert('KING! KING!');
}
</script>
Changes in HTML5
Related Tags