⌘K

Developer

URL Encoding

URL encoding, also called percent-encoding, replaces characters that have a special meaning or are unsafe in a URL with a percent sign followed by their hexadecimal byte value.

Updated 12 Aug 2026

Why URLs need escaping

A URL is not free text. Characters such as ?, &, =, /, # and space each carry structural meaning, so a value containing them would change how the URL is parsed. Percent-encoding replaces each unsafe byte with %XX, letting arbitrary text ride safely inside a path or query parameter.

Which characters are safe

  • Unreserved and always safe: A–Z, a–z, 0–9, hyphen, underscore, period and tilde
  • Reserved and escaped when used as data: ? & = # / : @ + and space
  • Space becomes %20 in paths, and may be + in traditional form submissions
  • Non-ASCII text is encoded as its UTF-8 bytes, so é becomes %C3%A9

Encode the part, not the whole

In JavaScript, encodeURI is meant for a complete URL and deliberately leaves structural characters alone. encodeURIComponent is for a single value and escapes them. Using the wrong one is the usual cause of parameters that silently truncate at an ampersand.

Double encoding

Encoding an already-encoded value turns %20 into %2520. Decode first, or encode exactly once at the boundary.

Encoding the whole URL

Escaping :// and ? breaks the URL structure entirely.

Forgetting the plus sign

In form-encoded bodies + means space, so a literal plus must be sent as %2B.

URL Encoder

Convert values safely and spot double-encoding at a glance.

Try URL Encoder

Characteristics

  • Each unsafe byte becomes % followed by two hex digits
  • Based on UTF-8 bytes, so one character may produce several escapes
  • Reversible and lossless
  • Rules differ slightly between path segments, query strings and form bodies

Common uses

  • Placing search terms and filters in query strings
  • Building safe redirect and callback URLs in OAuth flows
  • Encoding filenames and identifiers inside paths
  • Submitting HTML forms as application/x-www-form-urlencoded

Advantages

  • Lets any text travel inside a URL without ambiguity
  • Universally implemented in browsers, servers and libraries
  • Fully reversible
  • Preserves non-ASCII characters through UTF-8

Limitations

  • Encoded URLs are hard for people to read
  • Expands length, and URLs have practical limits
  • Easy to apply twice, producing broken values
  • Context-dependent rules trip up developers regularly

Examples

Encoding a value that contains reserved characters
Raw:     search?q=tea & coffee/café
Encoded: search?q=tea%20%26%20coffee%2Fcaf%C3%A9

Double-encoded (wrong): q=tea%2520%2526%2520coffee

Frequently asked questions

What is URL encoding used for?

Putting text that contains reserved or non-ASCII characters into a URL without breaking its structure.

Why is a space shown as %20?

Spaces are not permitted in URLs, so they are replaced by the percent-encoded value of the space byte.

What is the difference between encodeURI and encodeURIComponent?

encodeURI preserves structural characters for a whole URL; encodeURIComponent escapes them and is correct for a single value.

How do I fix a double-encoded URL?

Decode until the value stops changing, then encode exactly once when you rebuild the URL.

Is URL encoding the same as Base64?

No. URL encoding escapes unsafe characters in place; Base64 re-encodes bytes into a different alphabet.

Related terms

All terms

Related tools

Related guides

All guides