HTML Guides for inline
Learn how to identify and fix common HTML validation errors flagged by the W3C Validator — so your pages are standards-compliant and render correctly across every browser. Also check our Accessibility Guides.
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>
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.
Pro Trial
Full Pro access. Cancel anytime.
Start Pro Trial →Join teams across 40+ countries