# Bad value X for attribute “href” on element “a”: Expected a slash ("/").

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

A valid URL consists of several parts: a scheme (like `https`), followed by `://`, then the host, and optionally a path, query string, and fragment. The `://` separator — a colon followed by two forward slashes — is a required part of the URL syntax for schemes like `http` and `https`. When one of these slashes is missing, the browser may fail to navigate to the intended destination, interpret the value as a relative path, or behave unpredictably across different environments.

This error commonly occurs due to simple typos, copy-paste mistakes, or programmatic URL construction where string concatenation goes wrong. While some browsers may attempt to correct malformed URLs, you should never rely on this behavior. A malformed `href` can break navigation entirely, cause security warnings, produce unexpected redirects, or confuse assistive technologies like screen readers that announce link destinations to users.

Beyond the missing-slash case, this error can also appear when other parts of the URL contain characters that aren't valid without proper encoding — for instance, spaces or special characters that should be percent-encoded. Always ensure your URLs conform to the [URL Standard](https://url.spec.whatwg.org/).

## How to Fix

1. **Check the scheme separator**: Verify that the protocol is followed by `://` (colon and two slashes). For example, `https://` not `https:/` or `https:`.
2. **Validate the full URL**: Paste the URL into a browser's address bar to confirm it resolves correctly.
3. **Encode special characters**: If the URL contains spaces or special characters, use proper percent-encoding (e.g., spaces become `%20`).
4. **Review dynamically generated URLs**: If URLs are built through string concatenation or template logic, double-check that all parts are joined correctly.

## Examples

### Incorrect: Missing a slash after the scheme

```html
<a href="https:/example.com">Visit Example</a>
```

The validator reports this because `https:/example.com` has only one slash after the colon instead of the required two.

### Incorrect: Missing both slashes

```html
<a href="https:example.com">Visit Example</a>
```

This is also invalid — the colon must be followed by `//` for `https` URLs.

### Correct: Properly formatted URL

```html
<a href="https://example.com">Visit Example</a>
```

### Correct: URL with a path

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

### Correct: URL with encoded spaces

```html
<a href="https://example.com/search?q=hello%20world">Search</a>
```

### Incorrect: Unencoded space in URL

```html
<a href="https://example.com/my page">My Page</a>
```

Spaces are not valid in URLs. Use `%20` or `+` (in query strings) instead:

```html
<a href="https://example.com/my%20page">My Page</a>
```
