How to URL encode text
- Type or paste the text into the left box. The encoded result appears on the right as you type.
- Choose how to encode it under Encode as:
- Component (encodeURIComponent) for a single query value, path segment or anything you put inside a URL. This is the default and the safe choice.
- Full URL (encodeURI) to clean up a complete link with spaces or accents without breaking its
://,?and&. - Form data (+ for spaces) for
application/x-www-form-urlencodedbodies and query strings built like an HTML form.
- Tick Each line separately to encode a list of values in one go.
- Press Copy. To check the result, press Swap ⇄ or open the URL decoder.
encodeURI vs encodeURIComponent
Both percent-encode text as UTF-8; the difference is which characters they leave alone. encodeURI assumes you are giving it a whole URL, so it keeps the reserved characters that separate its parts. encodeURIComponent assumes you are giving it one value, so it encodes those too. Form encoding goes one step further and also encodes ! ' ( ) ~, with + for spaces. What each mode does to each character (computed by the encoder above, and identical to the browser's own functions):
| Character | encodeURIComponent | encodeURI | Form (+) |
|---|---|---|---|
| space | %20 | %20 | + |
! | ! | ! | %21 |
" | %22 | %22 | %22 |
# | %23 | # | %23 |
$ | %24 | $ | %24 |
% | %25 | %25 | %25 |
& | %26 | & | %26 |
' | ' | ' | %27 |
( | ( | ( | %28 |
) | ) | ) | %29 |
* | * | * | * |
+ | %2B | + | %2B |
, | %2C | , | %2C |
/ | %2F | / | %2F |
: | %3A | : | %3A |
; | %3B | ; | %3B |
= | %3D | = | %3D |
? | %3F | ? | %3F |
@ | %40 | @ | %40 |
[ | %5B | %5B | %5B |
] | %5D | %5D | %5D |
~ | ~ | ~ | %7E |
é | %C3%A9 | %C3%A9 | %C3%A9 |
😀 | %F0%9F%98%80 | %F0%9F%98%80 | %F0%9F%98%80 |
Greyed-out cells are left as they are. The practical rule: build URLs from encoded pieces. Using encodeURI on a value is the most common bug, because it lets & and = through. Passing a return URL as a parameter:
- Correct, with encodeURIComponent:
https://example.com/login?next=https%3A%2F%2Fexample.org%2Fcart%3Fid%3D42%26ref%3Dmail - Broken, with encodeURI:
https://example.com/login?next=https://example.org/cart?id=42&ref=mail. The server seesnext=https://example.org/cart?id=42and a separateref=mailparameter.
URL encoding examples
| Text | Mode | Encoded |
|---|---|---|
Hello World! | encodeURIComponent | Hello%20World! |
Hello World! | Form (+) | Hello+World%21 |
café & crème | encodeURIComponent | caf%C3%A9%20%26%20cr%C3%A8me |
50% off | encodeURIComponent | 50%25%20off |
https://example.com/a path/?q=café&x=1#top | encodeURI | https://example.com/a%20path/?q=caf%C3%A9&x=1#top |
https://example.com/a path/?q=café&x=1#top | encodeURIComponent | https%3A%2F%2Fexample.com%2Fa%20path%2F%3Fq%3Dcaf%C3%A9%26x%3D1%23top |
Which characters need URL encoding?
RFC 3986 splits characters into three groups:
- Unreserved:
A–Z a–z 0–9 - . _ ~. Always safe, never need encoding. - Reserved:
: / ? # [ ] @and! $ & ' ( ) * + , ; =. They have a job in URLs (separating the scheme, host, path, query and parameters), so encode them whenever they are part of your data. - Everything else: spaces,
" % < > \ ^ ` { | }, control characters and every non-ASCII character. These must always be encoded. Non-ASCII text is first converted to UTF-8, so one character can become up to four %XX codes.
Spaces: %20 or +?
%20 is the space in every part of a URL. + is a space only in the query string and in form bodies, a convention from HTML forms (application/x-www-form-urlencoded). That is why a literal plus sign in a query value must be sent as %2B: otherwise the server reads it as a space, a classic bug with phone numbers like +1 555 0100 and with Base64 values. When in doubt, use %20.
URL encode in JavaScript, Python, PHP, Java and C#
// JavaScript
encodeURIComponent("café & crème"); // "caf%C3%A9%20%26%20cr%C3%A8me"
new URLSearchParams({ q: "café au lait" }).toString(); // "q=caf%C3%A9+au+lait"
# Python
from urllib.parse import quote, quote_plus, urlencode
quote("café & crème", safe="") # %20 for spaces
urlencode({"q": "café au lait"}) # + for spaces
// PHP: rawurlencode() uses %20, urlencode() uses +
rawurlencode("café & crème");
// Java (form style, + for spaces)
URLEncoder.encode("café & crème", StandardCharsets.UTF_8);
// C#
Uri.EscapeDataString("café & crème"); // %20 for spacesRelated developer tools
- URL decoder: decode %XX codes and see every query parameter of a link.
- Base64 encoder: for binary data or files you need to put in a URL or JSON.
- JWT decoder: read the URL-safe Base64 parts of a JSON Web Token.
Frequently asked questions
How do I URL encode a string?
Type or paste it into the URL encoder: unsafe characters are replaced with %XX codes as you type. Each character is converted to UTF-8 bytes and every byte that isn't allowed is written as % plus two hex digits, so a space becomes %20 and é becomes %C3%A9. In JavaScript use encodeURIComponent(); in Python, urllib.parse.quote().
What is the difference between encodeURI and encodeURIComponent?
encodeURI() is for a complete URL: it leaves the characters that give a URL its structure (: / ? # & = and a few more) alone and only encodes spaces, non-ASCII and other unsafe characters. encodeURIComponent() is for one piece, such as a query value or path segment: it also encodes & = ? / # : + , ; @ $, so the value can't break the URL. Use encodeURIComponent for values; it's the right choice most of the time.
Should I encode spaces as %20 or +?
Use %20 in paths and whenever you are unsure: it means a space everywhere. + means a space only in query strings and form data (application/x-www-form-urlencoded), which is what HTML forms and URLSearchParams produce. In a path, + stays a plus sign. Choose "Form data (+ for spaces)" to get the + style.
Which characters need to be URL encoded?
Letters, digits and - . _ ~ never need encoding. The reserved characters : / ? # [ ] @ ! $ & ' ( ) * + , ; = must be encoded when they are part of a value rather than the URL's structure. Everything else, including spaces, quotes, %, <, >, {, }, | and all non-ASCII characters such as é or emoji, must always be encoded.
Can I URL encode emoji and non-English text?
Yes. The text is converted to UTF-8 first and each byte is percent-encoded, which is what browsers and servers expect: 😀 becomes %F0%9F%98%80 and 日本 becomes %E6%97%A5%E6%9C%AC. Browsers often show the decoded characters in the address bar, but send the encoded form.
How do I URL encode in Python?
Use urllib.parse: quote("a b/c") gives a%20b/c (it keeps / by default; pass safe="" to encode it too), quote_plus("a b") gives a+b for form data, and urlencode({"q": "café au lait"}) builds a whole query string: q=caf%C3%A9+au+lait.
Why is my text encoded twice (%2520)?
%25 is the encoded percent sign, so %2520 means an already-encoded %20 was encoded again. It happens when two layers of code both encode the same value, for example you call encodeURIComponent() and then a library encodes the URL again. Encode each value exactly once, at the point where you build the URL.
Is URL encoding a form of encryption?
No. It only makes text safe to put in a URL, and anyone can reverse it with a URL decoder. Don't put passwords or secrets in URLs, encoded or not: URLs end up in browser history, server logs and Referer headers.
Is my text sent anywhere when I encode it?
No. Encoding runs in JavaScript in your browser; nothing you type is uploaded, logged or saved. Only your options, such as the encoding mode, are remembered on this device.