HTML · Document structure

script

Loads or embeds JavaScript. Use defer for scripts that depend on the DOM and type="module" for modern module code.

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

Example

Try it

Notes

Prefer defer over placing scripts at the end of body. Avoid inline scripts when a Content-Security-Policy is active.

More in this group

<!doctype html> base body head html link meta charset meta description

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course