<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>
  1. Inside an element where metadata content or phrasing content is allowed, code one or more optional script elements.
  2. 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.
  3. Specify the URL of the external JavaScript code in the src attribute.
  4. Include any other attributes of the <script> tag as appropriate.
  5. 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>
  1. Inside an element where metadata content or phrasing content is allowed, code one or more optional script elements.
  2. 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.
  3. Include any other attributes of the <script> tag as appropriate.
  4. Include the JavaScript code between the starting and ending <script> tags.
  5. End the script element with a matching </script> closing tag.