# Bad value  for attribute “href” on element “a”: Illegal character in query. Space is not allowed.

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-for-attribute-href-on-element-a-illegal-character-in-query-space-is-not-allowed
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

A space character in the `href` attribute of an `<a>` element is not valid in a URL. Spaces must be encoded as `%20` in the query string.

URLs follow the syntax defined in [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986), which does not allow literal space characters anywhere in the URL. When the W3C validator encounters a space in a query string, it flags the `href` value as malformed. Browsers often handle this gracefully by encoding the space automatically, but the HTML itself is still invalid.

The query component of a URL (everything after the `?`) follows the same rule. If a value in the query string contains a space, replace each space with `%20`. An alternative encoding, `+`, is specific to the `application/x-www-form-urlencoded` format used by HTML form submissions, and is also accepted in practice by most servers. However, `%20` is the universally correct percent-encoding for a space in any part of a URL.

## Invalid example

```html
<a href="https://example.com/search?query=hello world&lang=en">Search</a>
```

The space between `hello` and `world` causes the validation error.

## Valid example

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

Every space in the URL is replaced with `%20`, and the markup passes validation.
