Skip to: content, navigation

by Ian Lloyd

defer (HTML attribute)

Browser support full matrix
IE5.5+ FF2 Saf3 Op9.5
Full None None None
Spec
Depr. Version
No HTML 4
defer="defer"

Example

A script with defer to stop the alert taking place too early (at which point the button being referred to does not yet exist):

<script type="text/javascript" defer>
alert(document.forms[0].cmdButton.value);
</script>
…
<form>
<input type="submit" name="cmdButton" value="Send it">
</form>

Description

The defer attribute is little more than a hint that the browser should maybe, possibly, if it feels like it, defer the execution of a script until later on when it’s finished the job of downloading the page content, as the script is not going to affect/modify the content of the page in any way shape or form.

In the example above, Internet Explorer honors the defer attribute and correctly identifies the button’s name.

The example shows the attribute being expressed in HTML 4.01. The XHTML syntax would be:

<script type="text/javascript" defer="defer">
…
</script>

However, the only browser that supports it is also the one browser on the list that cannot properly handle an XHTML document when served with the correct MIME-type.

Value

"defer" only

Compatibility

IE5.5Full
6.0Full
7.0Full
Firefox1.0None
1.5None
2.0None
Safari1.3None
2.0None
3.0None
Opera9.2None
9.5None

Very poor support - only Internet Explorer honored the defer attribute, all others ignored its presence. A better option is to use unobtrusive JavaScript techniques that are called using a window.onload event handler (or similar).

User-contributed notes

There are no comments yet.

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

The Principles of Beautiful Web Design

Best Seller!

You don’t need to go to Art School to design great looking web sites!

Book Cover: The Principles of Beautiful Web Design

Download the FREE sample chapters