# Bad value X for attribute “href” on element “a”: Backslash ("") used as path segment delimiter.

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-x-for-attribute-href-on-element-a-backslash-used-as-path-segment-delimiter
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

The `href` attribute on an `<a>` element must contain a valid URL as defined by the [WHATWG URL Standard](https://url.spec.whatwg.org/). According to this standard, the forward slash (`/`) is the only recognized path segment delimiter. Backslashes (`\`) have no defined role in URL path syntax and are treated as invalid characters by the validator.

This issue most commonly occurs when developers copy file paths from Windows, which uses backslashes as its native path separator, directly into HTML. For example, copying a path like `images\photos\sunset.jpg` from Windows Explorer and pasting it into an `href` attribute will trigger this validation error.

While most modern browsers will silently normalize backslashes to forward slashes, relying on this behavior is problematic for several reasons:

- **Standards compliance:** Your HTML fails validation, which can mask other real issues in your code.
- **Interoperability:** Not all HTTP clients, crawlers, or tools normalize backslashes. Search engine bots, link checkers, or older browsers may fail to follow the link correctly.
- **Portability:** Code that depends on browser error correction is fragile and may break in unexpected environments, such as server-side rendering, email clients, or embedded web views.
- **Accessibility:** Screen readers and assistive technologies that parse `href` values may not handle backslashes consistently, potentially breaking navigation for users who rely on these tools.

To fix the issue, simply replace every backslash (`\`) with a forward slash (`/`) in any URL used in an `href` attribute. This applies not only to `<a>` elements but to any attribute that expects a URL, such as `src`, `action`, or `data`.

## Examples

### Incorrect: backslash used as path delimiter

```html
<a href="docs\guide\intro.html">Introduction</a>
```

### Correct: forward slash used as path delimiter

```html
<a href="docs/guide/intro.html">Introduction</a>
```

### Incorrect: backslashes in an absolute URL

```html
<a href="https://example.com\blog\2024\post.html">Read the post</a>
```

### Correct: forward slashes in an absolute URL

```html
<a href="https://example.com/blog/2024/post.html">Read the post</a>
```

### Incorrect: mixed slashes

Sometimes a URL contains a mix of forward and backslashes, which still triggers the error:

```html
<a href="assets/images\photo.jpg">View photo</a>
```

### Correct: all forward slashes

```html
<a href="assets/images/photo.jpg">View photo</a>
```

## Tips for avoiding this issue

- **Search and replace:** If you're migrating content or working with paths generated on Windows, do a global find-and-replace of `\` with `/` across your HTML files.
- **Editor settings:** Many code editors can highlight or auto-fix invalid URL characters. Enable linting tools or HTML validation plugins to catch this early.
- **Build tools:** If your build process generates links from file system paths, ensure it normalizes path separators to forward slashes before writing them into HTML output.
- **URL encoding:** If you genuinely need a literal backslash character within a URL (which is extremely rare), it must be percent-encoded as `%5C`. However, this is almost never the intended behavior when this validation error appears.
