<script> Tag Syntax
Rules for coding HTML script
elements
<head> ... metadata content ... <title>... text content ...</title> ... <script type="text/javascript" src="..."></script> <script type="text/javascript"> ... JavaScript code ... </script> ... </head>
<script> Content Model
Contents of the <script> Tag
How to code a script element with an external script resource
<script type="text/javascript" src="..."></script>
- Inside an element where metadata content or phrasing content is allowed, code one or more optional script elements.
- Begin the script element with a starting <script> tag. The element name uses lower case letters and should be in the HTML namespace, which it will pick up automatically from the
xmlns
attribute on the <html> tag. - Specify the URL of the external JavaScript code in the
src
attribute. - Include any other attributes of the <script> tag as appropriate.
- End the script element with a matching
</script>
closing tag.
How to code a script element with inline script code
<script type="text/javascript"> ... JavaScript code ... </script>
- Inside an element where metadata content or phrasing content is allowed, code one or more optional script elements.
- Begin the script element with <script>. The element name uses lower case letters and should be in the HTML namespace, which it will pick up automatically from the
xmlns
attribute on the <html> tag. - Include any other attributes of the <script> tag as appropriate.
- Include the JavaScript code between the starting and ending <script> tags.
- End the script element with a matching
</script>
closing tag.