HTML <script> deferAttributes

HTML script 标签参考手册HTML <script> Tag

Examples

The script will only run after the page has finished loading:

<script src="demo_defer.js.html" defer></script>

Try it Yourself »

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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 after the page has finished loading.

Note:The defer attribute applies only to external scripts (only when the src attribute is used).

Note:There are several ways to execute external scripts:

  • If async="async": the script is executed asynchronously relative to the rest of the page (the script will be executed while the page continues parsing).
  • If async is not used and defer="defer": the script will be executed when the page has finished parsing.
  • If neither async nor defer is used: the script is read 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">.


Syntax

<script defer>


HTML script 标签参考手册HTML <script> Tag Other Extensions