# The “type” attribute is unnecessary for JavaScript resources.

> Canonical HTML version: https://rocketvalidator.com/html-validation/the-type-attribute-is-unnecessary-for-javascript-resources
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

The `<script>` element's `type` attribute specifies the MIME type of the script. In earlier HTML versions (HTML 4 and XHTML), the `type` attribute was required and authors had to explicitly declare `type="text/javascript"`. However, the HTML5 specification changed this — JavaScript is now the default scripting language, so when the `type` attribute is omitted, browsers automatically treat the script as JavaScript.

Because of this default behavior, including `type="text/javascript"` (or variations like `type="application/javascript"`) is unnecessary. The W3C HTML Validator raises a warning to encourage cleaner, more concise markup. While this isn't an error that will break your page, removing the redundant attribute keeps your HTML lean and aligned with modern standards.

There are legitimate uses for the `type` attribute on `<script>` elements, such as `type="module"` for ES modules or `type="application/ld+json"` for structured data. These values change the behavior of the `<script>` element and should absolutely be kept. The validator only flags the attribute when its value is a JavaScript MIME type, since that's already the default.

## Examples

### Incorrect — unnecessary `type` attribute

```html
<script type="text/javascript" src="app.js"></script>
```

```html
<script type="text/javascript">
  console.log("Hello, world!");
</script>
```

### Correct — `type` attribute removed

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

```html
<script>
  console.log("Hello, world!");
</script>
```

### Correct — `type` attribute used for non-default purposes

The `type` attribute is still necessary and valid when you're using it for something other than plain JavaScript:

```html
<!-- ES module -->
<script type="module" src="app.mjs"></script>

<!-- JSON-LD structured data -->
<script type="application/ld+json">
  {
    "@context": "https://schema.org",
    "@type": "Organization",
    "name": "Example Inc."
  }
</script>

<!-- Import map -->
<script type="importmap">
  {
    "imports": {
      "utils": "./utils.js"
    }
  }
</script>
```

### Quick fix checklist

- Search your HTML files for `type="text/javascript"` and `type="application/javascript"`.
- Remove the `type` attribute from those `<script>` tags entirely.
- Leave the `type` attribute on any `<script>` tags that use `type="module"`, `type="importmap"`, `type="application/ld+json"`, or other non-JavaScript MIME types.
