References

Beginner-friendly references for web development, with live, editable examples.

The HTML defer attribute

Attribute All modern browsers Updated
Quick answer

The HTML defer attribute downloads the script in parallel and runs it in order after the document has been parsed. It is used on the <script> element.

Overview

The defer attribute downloads the script in parallel and runs it in order after the document has been parsed. It applies to the <script> element.

defer preserves execution order and guarantees the DOM is ready, making it the safe default for most scripts in the <head>.

Syntax

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

Values

Value
A boolean attribute — present or absent.

Best practices

  • Declare the character encoding with <meta charset="utf-8"> first in the <head>.
  • Load scripts with defer (or as modules) so they do not block parsing.
  • Protect third-party resources with integrity and crossorigin (Subresource Integrity).
  • Use resource hints like preload deliberately, paired with the right as value.

Frequently asked questions

What does the defer attribute do?
Defers script execution until after parsing.
Where do head attributes apply?
On the metadata elements in the <head><meta>, <link>, <script> and <base>.
What is the difference between async and defer?
async runs a script as soon as it loads in no set order; defer runs scripts in order after the document is parsed.
Which elements use the defer attribute?
It is an element-specific attribute, used on document head elements like <meta>, <link> and <script>.