The Script Tag

Learn how the <script> tag connects JavaScript to your HTML page — and why where you place it matters more than you think.

Step 1 of 5

Plugging JavaScript into HTML

You've been writing JavaScript in the browser console, but real web pages need their JS code loaded automatically when the page opens. The `<script>` tag is how you connect JavaScript to an HTML document. Without it, your HTML page has no idea that any JavaScript exists. The browser reads your HTML file top-to-bottom, and when it encounters a `<script>` tag, it knows: 'Time to run some JavaScript.'

Think of it this way: The `<script>` tag is like plugging in a power cord — it connects your JavaScript brain to the HTML body. Where you plug it in matters: plug a lamp into a socket behind the couch and it works fine, but plug a refrigerator into a weak extension cord and you'll blow a fuse.
Learn more on MDN
HTMLREAD ONLY