HTML defer Attribute
The HTML "defer" attribute specifies that a script is executed when a page has finished the parsing. It is a boolean attribute. This attribute works for external scripts and must be used only when the "src" attribute is present.
You can use this attribute on the <script> element.
An external script can be executed in the following ways:
- When "async" is present, the script will be executed asynchronously while the page continues the parsing.
- When "async" is not present but "defer" is present, the script will be executed when the page finishes the parsing.
- When neither "async" or "defer" is present, the script will be executed immediately before the browser continues the parsing.
<script src="example.js" defer></script>
Example of the HTML "defer" attribute: