script
Loads or contains JavaScript.
Learn script, noscript, template as part of the HTML element system: when to use it, how it fits inside a document and what mistakes to avoid.
Scripting
The script element loads or contains JavaScript. noscript provides fallback content when scripts are disabled. template stores inert markup that scripts can clone later.
JavaScript is powerful, but loading it carelessly can block rendering, break accessibility or make the page unusable when scripts fail.
script, noscript, template. JavaScript loading, fallback content and reusable hidden markup. Syntax in context
Use defer or type=module for most external scripts. Keep critical content in HTML when possible.
<script defer src="assets/js/app.js"></script>
<noscript>This lesson still shows the core content without JavaScript.</noscript>
<template id="lesson-card">
<article class="card">
<h2></h2>
<p></p>
</article>
</template>
Good versus weak
<script defer src="assets/js/app.js"></script>
<noscript>This lesson still shows the core content without JavaScript.</noscript>
<template id="lesson-card">
<article class="card">
<h2></h2>
<p></p>
</article>
</template>
<script src="huge-app.js"></script> <div id="app"></div>
Rules that matter
Most classic external scripts should not block parsing.
type=module scripts are deferred by default.
Use async for scripts that do not depend on the DOM or on another script order.
Do not make a blank page that only works after JavaScript loads.
Template content is not rendered until script uses it.
Production thinking
Beginners often ask why this is not just a div with styling. The reason is that HTML is read by browsers, search engines, screen readers and future developers. Clear meaning makes the page easier to use and maintain.
If JavaScript controls important UI, make sure keyboard support, focus management and fallback behavior are handled.
Script loading affects performance, reliability and security. Audit third-party scripts carefully.
Live code lab
Edit the HTML or CSS, then use Run to refresh the preview. The preview is isolated, so links and forms stay inside this practice area.
Mini assignment
Practice assignment
Try it yourself
Self-check
Do not only read this page. Answer these questions out loud or write the answers in your own notes. If one answer feels vague, revisit the examples before moving on.