About this tool
URLs can only contain a limited set of characters. Anything else, such as spaces, &, #, accented letters or emoji, has to be percent-encoded: written as % followed by two hex digits for each byte. This URL encoder and decoder converts in both directions, and breaks any URL down into its protocol, host, path and decoded query parameters, so you can see exactly what a link contains.
How to use it
- Choose Encode or Decode.
- Choose the scope. Component encodes a single value, such as a search term or one path segment. Full URL encodes a whole address but keeps its structure (
:/?#&=) intact. - Turn on Spaces as + for HTML-form-style query strings.
- Paste a full URL to see the URL breakdown: each part, and every query parameter with its decoded value. Use the swap button (⇄) to feed the output back in.
encodeURIComponent vs. encodeURI
Component (encodeURIComponent) | Full URL (encodeURI) | |
|---|---|---|
| Use for | One query value or path segment | A complete URL that only needs unsafe characters fixed |
| Leaves unencoded | Letters, digits and - _ . ! ~ * ' ( ) | The same, plus ; , / ? : @ & = + $ # |
hello world&more | hello%20world%26more | hello%20world&more |
The classic bug is using encodeURI on a value: an & or # inside it stays as-is and breaks the URL. When in doubt, encode each value with Component mode, or let URLSearchParams do it.
Percent-encoding reference
| Character | Encoded | Character | Encoded |
|---|---|---|---|
| space | %20 (or + in forms) | & | %26 |
! | %21 | ' | %27 |
" | %22 | + | %2B |
# | %23 | , | %2C |
$ | %24 | / | %2F |
% | %25 | : | %3A |
= | %3D | ? | %3F |
@ | %40 | é | %C3%A9 |
[ ] | %5B %5D | 👋 | %F0%9F%91%8B |
Non-ASCII characters are first converted to UTF-8 bytes, and each byte is encoded, which is why é becomes two % codes and an emoji becomes four.
Space: %20 or +?
Both mean “space”, but in different places. %20 works everywhere in a URL. + means a space only in query strings in the application/x-www-form-urlencoded format, which HTML forms, URLSearchParams, PHP’s urlencode, Python’s quote_plus and Java’s URLEncoder use. In a path, + is a literal plus sign. If a server shows + where you expected spaces, or loses real plus signs (like in C++ or phone numbers), the two conventions were mixed up.
Encode and decode URLs in code
encodeURIComponent('hello world&more'); // "hello%20world%26more" (a value)
encodeURI('https://example.com/a b'); // "https://example.com/a%20b" (a whole URL)
// Easiest and safest: let URL / URLSearchParams do it
const url = new URL('https://example.com/search');
url.searchParams.set('q', 'hello world&more');
url.toString(); // "https://example.com/search?q=hello+world%26more"from urllib.parse import quote, quote_plus, urlencode, unquote
quote("a b/c&d", safe="") # 'a%20b%2Fc%26d'
quote_plus("a b/c&d") # 'a+b%2Fc%26d' (form style)
urlencode({"q": "hello world"}) # 'q=hello+world'
unquote("a%20b") # 'a b'<?php
rawurlencode('a b&c'); // "a%20b%26c" (RFC 3986, for paths and values)
urlencode('a b&c'); // "a+b%26c" (form style, spaces as +)
http_build_query(['q' => 'hello world']); // "q=hello+world"import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
URLEncoder.encode("a b&c", StandardCharsets.UTF_8); // "a+b%26c" (form style)Uri.EscapeDataString("a b&c"); // "a%20b%26c"
Uri.UnescapeDataString("a%20b"); // "a b"Common problems
- Double encoding: encoding an already-encoded string turns
%into%25, soa%20bbecomesa%2520b. Encode raw values once, at the point where you build the URL. - “URI malformed” when decoding: a
%isn’t followed by two hex digits (such as100%), or the bytes aren’t valid UTF-8. - Base64 in URLs: standard Base64 contains
+,/and=, which get mangled. Encode it, or use URL-safe Base64 from the Base64 tool.
FAQ
How do I URL-encode a string?
Choose Encode and Component, then paste the text. In JavaScript, use encodeURIComponent(value), or build the URL with URLSearchParams, which encodes for you.
What does %20 mean in a URL?
It is an encoded space: % followed by the character’s byte value in hex (0x20 is a space). In query strings, spaces are sometimes written as + instead.
What is the difference between encodeURI and encodeURIComponent?
encodeURIComponent encodes everything except letters, digits and - _ . ! ~ * ' ( ), so it is right for single values. encodeURI also leaves URL structure characters such as / ? & = # alone, so it is only for whole URLs.
When should I encode a URL?
Whenever you insert user input or arbitrary text into a URL, especially query parameter values, encode it with component mode. Otherwise characters like & and # will break the URL.
What is double encoding?
Encoding an already-encoded string turns % into %25 (so %20 becomes %2520). If you see %25 in a URL, something was encoded twice.
Why does decoding fail with "URI malformed"?
The input contains a % that is not followed by two hex digits, or the bytes do not form valid UTF-8.