FSM Full Stack Masterclass
Platform under construction
HTML course badge

HTML Attributes

Intermediate

HTML Script Attributes

Learn src, type, defer, async, nomodule, integrity, crossorigin as part of the HTML attribute system: what they configure, where they belong and which mistakes to avoid.

Scripts

Script attributes control how JavaScript loads.

The script element can block rendering, defer execution, load modules, check integrity and support cross-origin resources. Its attributes affect performance and reliability.

Many frontend bugs begin with script loading order. Knowing defer, async and type="module" prevents a lot of guessing.

Attribute group: src, type, defer, async, nomodule, integrity, crossorigin. Attributes that control JavaScript loading, modules and security checks.

What belongs here

Learn attributes by purpose, not by memorizing random names.

src

External JavaScript file to load.

defer

Downloads during parsing and runs after the document is parsed.

async

Downloads during parsing and runs as soon as ready.

type="module"

Loads the script as a JavaScript module.

nomodule

Fallback for older browsers that do not support modules.

integrity + crossorigin

Subresource integrity and cross-origin loading checks.

Syntax in context

Choose loading behavior deliberately.

Use defer for many normal scripts. Use async for independent scripts such as analytics. Use modules for modern app code.

<script defer src="assets/js/navigation.js"></script>
<script type="module" src="assets/js/app.js"></script>

Good versus weak

Small attribute choices can change behavior, accessibility and security.

Good

<script defer src="assets/js/navigation.js"></script>
<script type="module" src="assets/js/app.js"></script>

Weak

<script src="big-app.js"></script>
<script async src="depends-on-dom.js"></script>

Rules that matter

Use these rules before publishing real HTML.

Use defer for DOM-dependent scripts

Deferred scripts run after parsing, which avoids many missing-element bugs.

Use async only when independent

Async scripts can execute in unpredictable order.

Use modules for modern code

Modules are deferred by default and support imports.

Pin external scripts carefully

External scripts can affect security and performance.

Explain the loading choice

A script tag should make it obvious whether order, DOM readiness or independent loading matters.

Production thinking

Attributes are tiny pieces of HTML with real product impact.

Why does this matter?

Attributes are small, but they change how an element works. A good attribute can make a link usable, an image understandable, a form easier to complete or a script safer to load.

Accessibility

If JavaScript fails, important content should still be reachable or a noscript fallback should explain the requirement.

Production note

Script attributes affect load speed, execution order, caching, security and how safely third-party code enters the page.

Live code lab

Change the code and run the example.

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

Try this now.

  • Change one tag, attribute or text value in the example.
  • Run the preview and describe exactly what changed.
  • Reset the lab and repeat the same change without looking at the original.

Practice assignment

Do this before moving to the next lesson.

  1. Change one meaningful part of the HTML, not only the visible text.
  2. Run the preview and check whether the result still makes semantic sense.
  3. Explain why the element or attribute you changed belongs in this exact place.

Try it yourself

Script loading examples

Live preview

Self-check

Before you continue, prove that you own this lesson.

Intermediate

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.

  1. Can you explain what problem this lesson solves in a real website?
  2. Can you identify the most important tag or attribute from this lesson?
  3. Can you name one accessibility mistake this lesson helps prevent?
  4. Can you write one good example and one weak example without copying the page?
  5. Can you explain when you would use this in production and when you would avoid it?