URL Encoder / Decoder
Percent-encode text for safe use in a URL, or decode an already-encoded URL.
How this URL encoder works
Paste text or a URL and it's percent-encoded (or decoded) so special characters are safe to use inside a URL, using JavaScript's built-in encoding functions locally in your browser.
encodeURI vs. encodeURIComponent
JavaScript actually has two different encoding functions with different rules, and mixing them up is a very common source of bugs. encodeURIComponent encodes almost everything, including characters like &, =, and / — correct when encoding a single value that will go inside a query string parameter. encodeURI leaves those characters alone since it assumes you're encoding a whole URL that should keep its structural characters intact. Using encodeURI on a query parameter value that itself contains & will break the URL's parameter boundaries.
The special case of the plus sign
In a URL's query string, a literal space is sometimes represented as + (a convention from HTML form encoding, application/x-www-form-urlencoded) rather than %20. But percent-encoding functions like encodeURIComponent will encode an actual + character in your input as %2B, not treat it as a space. Confusing these two conventions is a frequent source of subtly broken URLs, especially with form data.
Frequently asked questions
What's the difference between encodeURI and encodeURIComponent?
encodeURIComponent encodes more characters (including &, =, and /) and is correct for encoding a single value to insert into a URL. encodeURI preserves those structural characters and is meant for encoding a complete URL.
Why does a plus sign in my input become %2B instead of staying as a space?
Percent-encoding functions treat a literal + character as data to encode, not as the form-encoding convention for a space. Those are two different, easily confused encoding schemes.
How do I avoid double-encoding a URL?
Only encode raw, unencoded values. If a string already contains %-encoded sequences and you encode it again, the % itself gets encoded to %25, corrupting the original encoding.