Latest web development tutorials

HTML script defer property

HTML script tags reference manual HTML <script> tag

Examples

After the page is loaded before running the script:

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

try it"

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support defer attribute.


Definition and Usage

defer attribute is a Boolean attribute.

After defer attribute specifies when the page has finished loading, it will execute the script.

Note: defer property applies only to external script (only when using the src attribute).

Note: There are several ways to perform an external script:

  • If async = "async": script asynchronously with respect to the rest of the page execution (when the page continues to be parsed, the script will be executed)
  • When the script execution will be completed parsing the page: If you do not use the async and defer = "defer"
  • If neither use nor async defer: Before the browser to continue parsing the page, immediately read and execute scripts

Differences between HTML 4.01 and HTML5

no.


Differences between HTML and XHTML

In XHTML, prohibit attribute minimization, defer property must be defined as <script defer = "defer">.


grammar

<script defer>


HTML script tags reference manual HTML <script> tag