HTML <script>
defer
Attribute
Example
The script runs only after the page has fully loaded:
Browser Support
All major browsers support the defer
attribute.
Definition and Usage
The defer
attribute is a boolean attribute.
The defer
attribute specifies that the script is executed when the page has finished parsing.
Note: The defer
attribute is only for external scripts (should only be used if the src
attribute is present).
Note: There are several ways to execute external scripts:
If
async="async"
: The script is executed asynchronously with the rest of the page (the script will be executed while the page continues the parsing)If
async
is not used anddefer="defer"
: The script is executed when the page has finished parsingIf neither
async
nordefer
is used: The script is fetched and executed immediately, before the browser continues parsing the page
Differences Between HTML 4.01 and HTML5
None.
Differences Between HTML and XHTML
In XHTML, attribute minimization is forbidden, and the defer
attribute must be defined as <script defer="defer">
.