CSS Portal

HTML defer Attribute

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
defer
HTML AttributeThis attribute is supported by all modern browsers.
Updated 28th March 2024

Description

The defer attribute is a boolean attribute used in <script> tags within HTML documents. When present, it specifies that the script is meant to be executed after the document has been parsed, but before firing the DOMContentLoaded event. This is particularly useful for scripts that don't need to be run immediately and can wait until the HTML is fully parsed, thus improving the loading time of the page by not blocking the rendering of the document.

Scripts with the defer attribute will maintain their execution order as they appear in the document. This means that if multiple scripts are marked with defer, they will execute in the order they are encountered in the document, ensuring any dependencies between scripts are respected. Unlike the async attribute, which also doesn't block the document's parsing but does not guarantee the order of execution, defer provides a way to keep scripts that depend on each other in the correct sequence.

The defer attribute is ignored if the <script> tag does not have a src attribute (i.e., if the script is inline). It is supported by all modern browsers and is a recommended practice for scripts that are not required to interact with the initial loading of the page. Using defer helps in optimizing the performance of web pages, making them more responsive and quicker to interact with.

Syntax

<script defer>

Values

The defer attribute is a boolean attribute, therefore no values are associated with this attribute.

Applies To

Example

&lt;script src="myScript.js" defer&gt;&lt;/script&gt;
Open in editor

Browser Support

The following information will show you the current browser support for the HTML defer attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.

This attribute is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee