%url-decoder.net

Invalid URL Characters: What Is Allowed and How to Fix It

Updated November 18, 2026 · 6 min read

Short answer

A URL may only contain letters, digits, - . _ ~ and the reserved delimiters : / ? # [ ] @ ! $ & ' ( ) * + , ; =. Everything else, including spaces, quotes, < > { } | \ ^ ` and every non-ASCII character, must be percent-encoded. A percent sign is allowed only as the start of a %XX sequence.

“Invalid URL”, “URI malformed” and links that break at a space all come from the same rule: a URL can carry only a small set of ASCII characters. Anything else has to be percent-encoded, written as % followed by two hex digits for each byte. This guide lists what is allowed, what is not, and what each common tool does when it meets an invalid character.

Characters that are allowed

  • Unreserved: A–Z a–z 0–9 - . _ ~. Always allowed, never need encoding.
  • Reserved delimiters: : / ? # [ ] @ and ! $ & ' ( ) * + , ; =. Allowed where they do their job (separating the parts of the URL). When they are part of a value, encode them.
  • Percent sign: only as the start of a %XX sequence. A literal % is written %25.

Characters that are never allowed unencoded

RFC 3986 does not allow these anywhere in a URL. The last column shows what the WHATWG URL parser, which browsers and Node.js use, does with each one in a path. It was generated by running the parser on https://example.com/a?b with each character in place of the question mark.

CharacterNameEncode asBrowser parser, in a path
SPSpace%20%20
"Quotation mark%22%22
<Less-than sign%3C%3C
>Greater-than sign%3E%3E
\Reverse solidus (backslash)%5Cturned into /
^Circumflex accent%5E%5E
`Grave accent (backtick)%60%60
{Left curly bracket%7B%7B
|Vertical line (pipe)%7Cleft as-is
}Right curly bracket%7D%7D

Two things stand out. The parser repairs most invalid characters by encoding them, which is why a link with a space often still works in a browser. But it leaves | and ^ untouched in a path, so a URL containing them is passed on unchanged even though RFC 3986 does not allow them. Encode them yourself. It also turns a backslash into a forward slash, which silently changes the path. Non-ASCII characters such as é are converted to UTF-8 and percent-encoded: /caf%C3%A9.

The errors you will see

  • TypeError: Invalid URL from new URL() when the text cannot be parsed as an absolute URL. Real results from Node.js:
    • new URL("example.com/page") → TypeError: Invalid URL (no scheme)
    • new URL("https://exa mple.com/") → TypeError: Invalid URL (space in the host). Browsers are not fully consistent here: in our tests Chrome accepted this host by encoding the space as %20, while Node.js rejected it, as the WHATWG URL Standard requires.
    • new URL("https://example.com:99999/") → TypeError: Invalid URL (port out of range)
  • URIError: URI malformed from decodeURIComponent when a % is not followed by two hex digits, or when the bytes are not valid UTF-8. The URL Decoder shows the exact position and can decode leniently. Every cause and fix is in how to fix URI malformed.
  • 400 Bad Request from a server that rejects a raw space or other invalid character in the request line instead of repairing it.

A colon in the first segment

A relative URL cannot start with a segment that contains a colon. RFC 3986 forbids it because a:b would be read as a URL with the scheme a. The parser does exactly that: resolved against https://example.com/dir/, a:b becomes a:b, while ./a:b becomes https://example.com/dir/a:b. Prefix the path with ./ or encode the colon as %3A.

How to fix an invalid URL

  1. Make sure it has a scheme, such as https://, if it is meant to be absolute.
  2. Encode each value separately with a component encoder (encodeURIComponent, Python's quote(s, safe='')) before joining the URL together. Do not encode the finished URL as one value.
  3. Never encode an already encoded value: that produces %2520.
  4. Check the result in the URL Parser. If it parses, the parser will also list any parameter that still looks encoded.

Questions

Which characters are not allowed in a URL?

Spaces, double quotes, < > { } | \ ^ ` and control characters are never allowed unencoded, and neither are non-ASCII characters such as é or emoji. They must be written as percent-encoded UTF-8 bytes, like %20 for a space.

Why does my browser accept a URL with spaces?

Browsers repair many invalid URLs before sending them: they percent-encode spaces, quotes and curly brackets in the path. Servers and other software are often stricter, so encode the URL yourself instead of relying on the repair.

What does "Invalid URL" mean in JavaScript?

new URL() throws TypeError: Invalid URL when the text cannot be parsed as an absolute URL, for example when the scheme is missing, the host contains a space or the port is out of range. Pass a base URL as the second argument to parse a relative URL.

Can a URL path start with a colon in its first segment?

Not in a relative URL. RFC 3986 says a segment containing a colon cannot be the first segment of a relative-path reference, because it would be read as a scheme. Write ./a:b instead of a:b.

See also

Try everything in this guide hands-on, free and entirely in your browser.

Check a URL in the URL Parser

Keep reading