URL Encode / Decode
Encode and decode URLs and query strings safely for HTTP requests, redirects and API calls.
Back to all tools on ToolForge
Result
About URL Encode / Decode
This URL encode/decode tool converts text to and from percent-encoded format entirely in your browser. URL encoding (also called percent-encoding) is necessary because certain characters have special meanings in URLs or are not safe for transmission in HTTP requests.
Why URL Encoding Is Necessary
URLs can only contain a limited set of characters (ASCII letters, digits, and a few special characters). When you need to include:
- Spaces: Encoded as
%20or sometimes+ - Non-ASCII characters: Chinese, Japanese, emoji, etc. get encoded as multiple byte sequences
- Special symbols: Characters like
< > # % { } | \ ^ ~ [ ] `must be encoded - Reserved characters in values: When
? & = / : @appear in parameter values (not as separators)
Common URL Encoding Examples
| Character | Encoded | Description |
|---|---|---|
(space) |
%20 |
Space character |
& |
%26 |
Query parameter separator |
= |
%3D |
Key-value separator |
? |
%3F |
Query string start |
# |
%23 |
Fragment identifier |
你好 |
%E4%BD%A0%E5%A5%BD |
Chinese characters |
encodeURI vs encodeURIComponent
JavaScript provides two encoding functions with different behaviors:
- encodeURI(): Encodes a complete URL but preserves reserved characters (
? & = / : @). Use for full URLs. - encodeURIComponent(): Encodes all special characters. Use for individual parameter values.
Example:
Input: https://example.com/search?q=hello world&type=article encodeURI result: https://example.com/search?q=hello%20world&type=article (keeps ? and & as-is) encodeURIComponent result: https%3A%2F%2Fexample.com%2Fsearch%3Fq%3Dhello%20world%26type%3Darticle (encodes everything)
Common Use Cases
- Query Parameters: Encoding parameter values that contain spaces or special characters
- Redirect URLs: Passing URLs as parameters (e.g.,
?redirect=https://...) - API Requests: Ensuring request bodies and headers are properly formatted
- Data URIs: Embedding data in URLs for tracking or state management
How to Encode or Decode URLs
- Enter your text: Type or paste the URL or text you want to encode/decode into the input box.
- Choose operation: Click "Encode" to convert text to percent-encoded format, or "Decode" to convert back to readable text.
- Review the result: The encoded or decoded text appears in the output box below.
- Copy or clear: Click "Copy Result" to copy the output, or "Clear" to start over.
Example Conversions
Encode example:
- Input:
https://example.com/search?q=hello world - Output:
https%3A%2F%2Fexample.com%2Fsearch%3Fq%3Dhello%20world
Decode example:
- Input:
%E4%BD%A0%E5%A5%BD%EF%BC%8C%E4%B8%96%E7%95%8C - Output:
你好,世界
Frequently Asked Questions
- What is URL encoding and why is it necessary?
- URL encoding (also called percent-encoding) converts characters into a format that can be safely transmitted over the internet. Special characters like spaces, ampersands, and non-ASCII characters must be encoded because they have reserved meanings in URLs or are not valid in certain contexts. For example, a space becomes %20, and Chinese characters get encoded as multiple percent-encoded bytes.
- What characters need to be encoded in a URL?
- The following characters typically need encoding: spaces (%20), special symbols (<, >, #, %, {, }, |, \, ^, ~, [, ], `, @), and non-ASCII characters (Unicode). Reserved characters like ? & = / : have special meanings in URL structure and should only be encoded when they appear in parameter values, not as structural separators.
- What is the difference between encodeURI and encodeURIComponent?
- encodeURI() encodes a complete URI but preserves reserved characters that have structural meaning (? & = / : @). encodeURIComponent() encodes all special characters and should be used for individual URL parameter values. For example, encodeURI('https://example.com?a=1&b=2') keeps the ? and &, while encodeURIComponent would encode them as %3F and %26.
- Why does my encoded URL look different in the browser address bar?
- Modern browsers automatically decode percent-encoded characters in the address bar for display purposes, showing a more readable version. However, the actual URL being sent to the server remains encoded. This is a visual convenience feature and does not affect how the URL functions.
- Can I decode a URL that was encoded multiple times?
- Yes, but you need to decode it the same number of times it was encoded. Double-encoded URLs contain percent signs that are themselves encoded (e.g., %2520 instead of %20). Decode once to get %20, then decode again to get the space character.