URL encoding (also called percent encoding) converts special characters into a format that can be safely transmitted in a URL. A space becomes %20, an ampersand becomes %26, and a hash becomes %23.
Why is URL encoding needed?
URLs can only safely contain a limited set of characters: letters (A–Z, a–z), digits (0–9), and the characters -, _, ., ~. Everything else — spaces, special characters, non-ASCII letters, emoji — must be percent-encoded or the URL breaks.
Common URL encoded characters
| Character | Encoded | Usage |
|---|---|---|
| Space | %20 or + |
Query strings |
& |
%26 |
When used in values |
= |
%3D |
When used in values |
+ |
%2B |
When literal + needed |
/ |
%2F |
Path separators in values |
? |
%3F |
When used in values |
# |
%23 |
Fragment identifiers |
@ |
%40 |
Email addresses in URLs |
encodeURI vs encodeURIComponent
These two JavaScript functions behave differently:
encodeURI(url)— encodes a complete URL. Preserves:,/,?,&,=,#because they are meaningful in a URL.encodeURIComponent(value)— encodes a URL component (like a query parameter value). Encodes everything including/and?.
Rule of thumb: Use encodeURIComponent for individual query parameter values. Use encodeURI for complete URLs.
Real-world examples
Encoding a search query with special characters:
Original: https://example.com/search?q=hello world & more
Encoded: https://example.com/search?q=hello%20world%20%26%20more
Encoding a URL parameter that contains another URL:
Original: ?redirect=https://example.com/path?foo=bar
Encoded: ?redirect=https%3A%2F%2Fexample.com%2Fpath%3Ffoo%3Dbar
How to URL encode or decode online
- Go to URL Encoder
- Paste your text or URL into the input
- Click Encode or Decode
- Copy the result