# Bad value X for attribute “type” on element “a”: Expected a token character or “/” but saw “ ” instead.

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-x-for-attribute-type-on-element-a-expected-a-token-character-or-but-saw-instead
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

The `type` attribute on an `<a>` element is an advisory hint that tells the browser what media type (MIME type) to expect at the linked resource. A valid MIME type follows a strict format: a type, a `/` separator, and a subtype (e.g., `text/html`, `application/pdf`, `image/png`). Each part must consist of token characters — letters, digits, and certain symbols — but **not** spaces.

This validation error occurs when the MIME type value contains a space or other unexpected character in a position where only token characters or a `/` are allowed. Common causes include:

- **Accidental spaces** within the MIME type (e.g., `application/ pdf` or `application /pdf`).
- **Multiple MIME types** separated by spaces (e.g., `text/html text/plain`), which is not valid since the attribute accepts only a single MIME type.
- **Typos or copy-paste errors** that introduce whitespace or non-token characters.

While the `type` attribute is purely advisory and browsers won't refuse to follow a link based on it, an invalid value defeats its purpose and signals sloppy markup. Standards-compliant HTML ensures your pages are interpreted consistently and avoids confusing tools, screen readers, or other user agents that may parse this attribute.

## Examples

### Incorrect: Space within the MIME type

```html
<a href="report.pdf" type="application/ pdf">Download Report</a>
```

The space after the `/` makes this an invalid MIME type.

### Incorrect: Multiple MIME types separated by a space

```html
<a href="data.csv" type="text/csv text/plain">Download Data</a>
```

The `type` attribute only accepts a single MIME type. The space between `text/csv` and `text/plain` triggers the error.

### Incorrect: Leading or trailing spaces

```html
<a href="photo.jpg" type=" image/jpeg ">View Photo</a>
```

Spaces before or after the MIME type are not permitted.

### Correct: Valid MIME type with no spaces

```html
<a href="report.pdf" type="application/pdf">Download Report</a>
```

### Correct: Other common valid MIME types

```html
<a href="data.csv" type="text/csv">Download Data</a>
<a href="photo.jpg" type="image/jpeg">View Photo</a>
<a href="archive.zip" type="application/zip">Download Archive</a>
```

### Correct: MIME type with a parameter

MIME types can include parameters separated by a semicolon — no spaces are required, though a single space after the semicolon is permitted per the MIME specification:

```html
<a href="page.html" type="text/html; charset=utf-8">View Page</a>
```

## How to Fix

1. **Inspect the `type` value** — look for any spaces within the type or subtype portions (before or after the `/`).
2. **Remove extra spaces** — ensure the value is a single, properly formatted MIME type like `type/subtype`.
3. **Use only one MIME type** — if you've listed multiple types, pick the one that accurately describes the linked resource.
4. **Verify the MIME type is valid** — consult the [IANA Media Types registry](https://www.iana.org/assignments/media-types/) to confirm you're using a recognized type.
5. **Consider removing the attribute** — since `type` is purely advisory on `<a>` elements, if you're unsure of the correct MIME type, omitting the attribute entirely is perfectly valid.
