HTML <script> defer Attribute
Example
<script src="demo-defer.js" defer></script>
Meaning
The defer attribute specifies that the browser might defer execution of the script enclosed by the <script> element.
Notes:
- async attribute is present: The script is downloaded in parallel to parsing the page, and executed as soon as it is available.
- defer attribute is present (and not async attribute): The script is downloaded in parallel to parsing the page, and executed after the page has finished parsing.
- Absence of async or defer: The script is downloaded and executed immediately, blocking parsing until the script is completed.
- The async attribute is only used for external scripts.
Standard Syntax
HTML: <script defer></script>
XHTML: <script defer="defer"></script>
Advertisement
Attribute Values
| Value | Description |
|---|---|
| defer | This is a boolean attribute, the presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value. |