# Bad value X for attribute “type” on element “script”: Subtype missing.

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-x-for-attribute-type-on-element-script-subtype-missing
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

A MIME type (also called a media type) is composed of two parts: a **type** and a **subtype**, separated by a forward slash (`/`) with no whitespace. For example, `text/javascript` has `text` as the type and `javascript` as the subtype. When you specify a value like `text` or `javascript` alone — without the slash and the other component — the validator reports this error because the subtype is missing.

This error commonly occurs when authors confuse the MIME type format with a simple label, writing something like `type="text"` or `type="javascript"` instead of the full `type="text/javascript"`. It can also happen due to a typo, such as accidentally omitting the slash or the subtype portion.

### Why this matters

Browsers rely on the `type` attribute to determine how to process the contents of a `<script>` element. An invalid MIME type can cause browsers to misinterpret or skip the script entirely. While modern browsers default to JavaScript when no `type` is specified, providing a malformed MIME type is not the same as omitting it — it may lead to unpredictable behavior across different browsers and versions. Keeping your markup valid also ensures better tooling support and forward compatibility.

### How to fix it

You have two main options:

1. **Provide a complete, valid MIME type.** For JavaScript, use `text/javascript`. For JSON data blocks, use `application/json`. For importmaps, use `importmap`.
2. **Remove the `type` attribute entirely.** Per the HTML specification, the default type for `<script>` is `text/javascript`, so omitting `type` is perfectly valid and is actually the recommended approach for standard JavaScript.

## Examples

### Incorrect: missing subtype

```html
<!-- "text" alone is not a valid MIME type -->
<script type="text" src="app.js"></script>
```

```html
<!-- "javascript" alone is not a valid MIME type -->
<script type="javascript" src="app.js"></script>
```

### Correct: full MIME type specified

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

### Correct: omitting the type attribute (recommended for JavaScript)

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

Since `text/javascript` is the default, omitting the attribute is the cleanest approach for standard JavaScript files.

### Correct: using type for non-JavaScript purposes

The `type` attribute is still useful when embedding non-JavaScript content in a `<script>` element. In these cases, always use the full MIME type:

```html
<script type="application/json" id="config">
  {"apiUrl": "https://example.com/api"}
</script>
```

```html
<script type="importmap">
  { "imports": { "lodash": "/libs/lodash.js" } }
</script>
```

### Common valid MIME types for `<script>`

| MIME Type | Purpose |
|---|---|
| `text/javascript` | Standard JavaScript (default) |
| `module` | JavaScript module |
| `importmap` | Import map |
| `application/json` | Embedded JSON data |
| `application/ld+json` | Linked Data / structured data |

Note that `module` and `importmap` are special values defined by the HTML specification and are not traditional MIME types, but they are valid values for the `type` attribute on `<script>` elements.
