# Bad value X for attribute “href” on element “a”: Illegal character in fragment. “[” is not allowed.

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

A `[` in the fragment of a link's URL, the part after `#`, has to be percent-encoded as `%5B`.

The URL Standard only allows square brackets around an IPv6 address in the host, as in `http://[::1]/`. Anywhere else, including the fragment, a valid URL writes `[` as `%5B` and `]` as `%5D`. Browsers still follow a link with raw brackets, but the `href` value isn't a valid URL, and the validator reports the first `[` it finds.

This often comes from long links copied out of a browser's address bar, such as map or search pages that keep coordinates or filters after the `#`. When the URL is that long (around 200 characters or more), the validator leaves it out of the message, which then reads `Bad value  for attribute "href"` with no value at all. To find the link, look for an `href` with a `[` after its `#`.

Encoding the brackets doesn't break links to elements on the same page. Browsers percent-decode the fragment when they look for a matching `id`, so `href="#step%5B2%5D"` still scrolls to `id="step[2]"`. For a link to another site, open the encoded URL once to check that the target page still reads its fragment correctly.

## Invalid example

```html
<a href="https://example.com/map#view:[40.64,-8.63]">Open the map</a>
```

## Valid example

```html
<a href="https://example.com/map#view:%5B40.64,-8.63%5D">Open the map</a>
```
