Skip to main content
HTML Validation

An inline “script” element (i.e., a “script” element without a “src” attribute and with a “type” attribute that is either unspecified, empty, or a JavaScript MIME type) must not have a “defer” attribute.

About This HTML Issue

The defer attribute is invalid on an inline <script>, because it only affects scripts that are loaded from an external file through the src attribute.

defer tells the browser to download an external script in parallel with parsing and run it after the document has finished parsing. An inline script has no external file to download, so there is nothing to defer and the browser runs it as soon as it is parsed. Because the attribute has no defined effect here, the validator flags it.

This usually happens when a template or a performance plugin adds defer to every <script> on the page, including the inline ones. The same applies to async, which is likewise only valid together with src.

Invalid example

<script defer>
console.log("Hello");
</script>

Valid example

Remove the defer attribute from the inline script:

<script>
console.log("Hello");
</script>

If you need the code to run after the document is parsed, move it into an external file and defer that instead:

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

Find issues like this automatically

Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.

Help us improve our guides

Was this guide helpful?
🌍 Trusted by teams worldwide

Validate at scale.
Ship accessible websites, faster.

Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.

Scheduled Reports
API Access
Open Source Standards
$7 / 7 days

Pro Trial

Full Pro access. Cancel anytime.

Start Pro Trial →

Join teams across 40+ countries