What is URL encoding (percent encoding)?
URL encoding replaces characters that have a special meaning in URLs
— or are unsafe to transmit — with a %XX
escape, where XX is the byte's hex value.
For example, a space becomes %20 and an
em-dash becomes %E2%80%94. The rules are
defined in RFC 3986.
Component vs Full URI — which mode should I pick?
- Component (
encodeURIComponent) escapes everything except a small unreserved set. Use it for the value of a query parameter, a path segment, or any string you plan to embed inside a larger URL — slashes, ampersands, and equals signs all get encoded. - Full URI (
encodeURI) leaves URL structure characters (/ : ? # & =) alone. Use it on an entire URL that's already well-formed but contains spaces or non-ASCII characters.
Common use cases
- Encoding query string values:
?q=hello%20world. - Form data sent as
application/x-www-form-urlencoded. - Building
mailto:and deep links with special characters in the body. - Safely embedding redirect URLs as a query parameter on an auth callback.
Privacy
Encoding and decoding happen in your browser using the built-in
encodeURIComponent / decodeURIComponent
APIs. The URL or text you paste never leaves your machine.