W3Schools.com

HTML5 <script> defer Attribute

HTML5 script Tag Reference HTML5 <script> tag

Example

A script that will not run until after the page has loaded:

<script type="text/javascript" src="demo_defer.js" defer="defer"></script>

Try it yourself »

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The defer attribute is supported in all major browsers.


Definition and Usage

The defer attribute is a boolean attribute.

When present, it 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 an external script can be executed:

  • 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 present and defer="defer": The script is executed when the page has finished parsing
  • If neither async or defer is present: The script is fetched and executed immediately, before the browser continues parsing the page

Differences Between HTML 4.01 and HTML5

None.


Syntax

<script defer="defer">

Note: The defer attribute is a boolean attribute, and can be set in the following ways:

  • <script defer>
  • <script defer="defer">
  • <script defer="">

HTML5 script Tag Reference HTML5 <script> tag
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE