# 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.

> Canonical HTML version: https://rocketvalidator.com/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
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

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

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

## Valid example

Remove the `defer` attribute from the inline script:

```html
<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:

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