Skip to the page
html reference · other

HTML <script> tag

closing tag
required
void element
no
lives inside
<head> or <body>
typically holds
JavaScript code, or nothing if src is set

Where it goes

Usually right before </body>. Then the page content shows first, and the script does not hold up the drawing while it downloads.

Example

<script src="app.js"></script>

Open this example in the editor →

Common mistakes

  • Putting it in <head> when the script needs tags that come later in the page. It runs before those tags exist.
  • Writing it self-closed, like <script src="app.js" />. It needs a real </script>. Without one, the browser treats the rest of the page as script.
  • Writing code inside a <script> that also has a src. The inside code is ignored. It is one or the other.

Related

Updated 24 October 2026. Practice it in the html route, or read more on MDN.