SyntaxStudy
Sign Up
HTML Intermediate 4 min read

Script in Head vs Body

Script Placement

Scripts in <head> without defer/async block rendering. Scripts at the end of <body> run after the page is visible.

Modern best practice: put scripts in <head> with defer for clean HTML structure.

Example
<!-- Old approach: scripts at end of body -->
<body>
  <p>Content here</p>
  <script src="app.js"></script>
</body>

<!-- Modern approach: defer in head -->
<head>
  <script src="app.js" defer></script>
</head>
Pro Tip

Use defer in <head> — it gives the same benefit as end-of-body placement with cleaner structure.