URL Encoder / Decoder
Encode text to URL-safe format or decode URL-encoded strings with automatic real-time transformation
Common Examples
URL Encoder / Decoder Documentation
Overview
The URL Encoder / Decoder is a simple yet essential tool for web developers, helping you safely encode text for use in URLs or decode URL-encoded strings back to readable text. Whether you're building APIs, debugging web requests, or working with query parameters, this tool ensures your URLs are properly formatted and compliant with web standards.
With automatic real-time transformation, bidirectional encoding/decoding, and instant copy functionality, you can quickly prepare data for HTTP requests, troubleshoot URL issues, and handle special characters with confidence.
Key Features
π Bidirectional Conversion
- Encode plain text to URL-safe format
- Decode URL-encoded strings to plain text
- One-click mode switching
- Swap input and output instantly
β‘ Real-Time Transformation
- Automatic conversion as you type
- No "submit" button needed
- Instant results
- Live character count
π Copy to Clipboard
- Copy input with one click
- Copy output with one click
- Fast workflow integration
- No manual selection needed
π Smart Mode Switching
- Toggle between encode/decode
- Swap button exchanges mode and values
- Preserves your data during switch
- Intuitive interface
π― Simple & Clean
- No configuration needed
- Straightforward interface
- Clear input/output separation
- Character counter for both fields
π Privacy Focused
- Client-side processing only
- No server uploads
- No data storage
- Completely offline after page load
How to Use
Encoding Text to URL Format
-
Select Encode Mode
- Ensure "Encode" button is selected (highlighted)
- Default mode when page loads
-
Enter Text
- Click in the "Plain Text" input area
- Type or paste your text
- Result appears automatically in "Encoded URL" field
-
Copy Result
- Click "Copy" button next to output
- Encoded text is copied to clipboard
- Paste into your application, URL, or code
Example:
Input: Hello World!
Output: Hello%20World%21
Decoding URL-Encoded Strings
-
Select Decode Mode
- Click "Decode" button
- Input/output fields switch labels
-
Enter Encoded URL
- Paste URL-encoded string
- Automatic decoding occurs
- Plain text appears in output
-
Copy Plain Text
- Click "Copy" on output field
- Use decoded text as needed
Example:
Input: Hello%20World%21
Output: Hello World!
Quick Mode Switch
- Click Swap Button (β icon between mode buttons)
- Mode switches (Encode β Decode)
- Input and output values swap
- Continue working immediately
Clearing Data
- Click "Clear" button to reset both fields
- Useful for starting fresh
- Character counts reset to 0
Use Cases
1. API Query Parameters
Scenario: Build URLs with query parameters that contain special characters for API requests.
Problem: Special characters in query parameters can break URLs or cause unexpected behavior.
Solution: Encode parameter values before adding to URL.
Example - Search Query:
Plain text: cats & dogs
Encoded: cats%20%26%20dogs
Full URL: https://api.example.com/search?q=cats%20%26%20dogs
Example - Complex Filter:
Plain text: price>100 AND category=electronics
Encoded: price%3E100%20AND%20category%3Delectronics
Full URL: https://api.example.com/products?filter=price%3E100%20AND%20category%3Delectronics
Use Cases:
- Search queries with spaces
- Filter parameters with operators
- User input in URL parameters
- Multi-word values
- Special characters (!, @, #, $, etc.)
Best Practices:
- Always encode user input before adding to URLs
- Encode each parameter value individually
- Don't encode the entire URL (only parameter values)
- Test with special characters to ensure proper encoding
2. Form Data Submission
Scenario: Prepare data for application/x-www-form-urlencoded POST requests.
Form Data Format:
key1=value1&key2=value2&key3=value3
Encoding Required When:
- Values contain spaces
- Values contain special characters
- Values contain
=or&characters - Sending non-ASCII characters
Example - User Feedback Form:
Name: John Doe
Email: john@example.com
Message: I love your product! Keep up the great work.
Encoded Form Data:
name=John%20Doe&email=john%40example.com&message=I%20love%20your%20product%21%20Keep%20up%20the%20great%20work.
Example - Login with Special Characters:
Username: admin@site
Password: P@ssw0rd!2024
Encoded:
username=admin%40site&password=P%40ssw0rd%212024
Implementation:
// JavaScript example
const formData = {
name: "John Doe",
email: "john@example.com",
message: "I love your product!"
};
const encoded = Object.entries(formData)
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
.join('&');
// Result: name=John%20Doe&email=john%40example.com&message=I%20love%20your%20product%21
3. OAuth & Authentication Redirects
Scenario: Build OAuth redirect URIs with encoded callback URLs.
OAuth Redirect Example:
Callback URL: https://myapp.com/auth/callback?user=12345
Encoded: https%3A%2F%2Fmyapp.com%2Fauth%2Fcallback%3Fuser%3D12345
Full OAuth URL:
https://oauth.provider.com/authorize?
client_id=abc123&
redirect_uri=https%3A%2F%2Fmyapp.com%2Fauth%2Fcallback%3Fuser%3D12345&
response_type=code
State Parameter with JSON:
State data: {"returnTo":"/dashboard","userId":"12345"}
Encoded: %7B%22returnTo%22%3A%22%2Fdashboard%22%2C%22userId%22%3A%2212345%22%7D
OAuth URL:
https://oauth.provider.com/authorize?
client_id=abc123&
state=%7B%22returnTo%22%3A%22%2Fdashboard%22%2C%22userId%22%3A%2212345%22%7D
Common OAuth Parameters to Encode:
redirect_uri- Your callback URLstate- Custom data to preservescope- Permission scopes (if contains spaces)login_hint- Email or username hints
Security Note: Always validate and sanitize state parameters on return to prevent injection attacks.
4. Email Links & mailto: URIs
Scenario: Create email links with pre-filled subject and body.
Basic mailto Link:
Email: support@example.com
Subject: Product Inquiry
Body: Hi, I have a question about your product.
Encoded:
mailto:support@example.com?subject=Product%20Inquiry&body=Hi%2C%20I%20have%20a%20question%20about%20your%20product.
Complex mailto Example:
Subject: Bug Report: Login Issue
Body:
Bug: Login button doesn't work
Steps:
1. Go to /login
2. Enter credentials
3. Click "Sign In"
Expected: Successful login
Actual: Page freezes
Encoded:
mailto:bugs@example.com?subject=Bug%20Report%3A%20Login%20Issue&body=Bug%3A%20Login%20button%20doesn%27t%20work%0ASteps%3A%0A1.%20Go%20to%20%2Flogin%0A2.%20Enter%20credentials%0A3.%20Click%20%22Sign%20In%22%0A%0AExpected%3A%20Successful%20login%0AActual%3A%20Page%20freezes
Special Characters in mailto:
- Space β
%20 - Newline β
%0A - Quote β
%22 - Comma β
%2C - Colon β
%3A
HTML Implementation:
<a href="mailto:support@example.com?subject=Help%20Request&body=I%20need%20assistance.">
Contact Support
</a>
5. Sharing Links with UTM Parameters
Scenario: Create marketing URLs with tracking parameters for analytics.
UTM Parameters:
Base URL: https://example.com/products
Campaign: Summer Sale 2024
Source: email newsletter
Medium: email
Content: header link
Encoded URL:
https://example.com/products?utm_campaign=Summer%20Sale%202024&utm_source=email%20newsletter&utm_medium=email&utm_content=header%20link
Social Media Share Link:
Share Text: Check out this amazing article about web development!
Article URL: https://blog.example.com/web-dev-tips
Hashtags: #webdev #coding #tutorial
Facebook Share:
https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fblog.example.com%2Fweb-dev-tips"e=Check%20out%20this%20amazing%20article%20about%20web%20development%21
Twitter Share:
https://twitter.com/intent/tweet?url=https%3A%2F%2Fblog.example.com%2Fweb-dev-tips&text=Check%20out%20this%20amazing%20article%20about%20web%20development%21&hashtags=webdev%2Ccoding%2Ctutorial
Benefits:
- Track campaign effectiveness
- Analyze traffic sources
- Measure conversion rates
- A/B test different messages
6. Debugging & Troubleshooting
Scenario: Decode URLs from logs, error messages, or API responses to understand what data was sent.
Example - API Error Log:
Error log shows:
GET /api/search?q=user%40example.com&filter=status%3Dactive
Decoded to understand:
GET /api/search?q=user@example.com&filter=status=active
Example - Webhook Payload:
Webhook URL received:
https://myapp.com/webhook?event=user.created&data=%7B%22id%22%3A123%2C%22email%22%3A%22user%40example.com%22%7D
Decoded data parameter:
{"id":123,"email":"user@example.com"}
Example - Browser Console:
Browser shows:
Failed to load: https://api.example.com/data?key=abc%20def&value=%2Fpath%2Fto%2Ffile
Decode to identify issue:
Failed to load: https://api.example.com/data?key=abc def&value=/path/to/file
Debugging Use Cases:
- Understand encoded error messages
- Verify correct parameter encoding
- Inspect API request URLs
- Analyze redirect chains
- Debug authentication flows
- Troubleshoot webhook deliveries
Technical Details
URL Encoding Standard
Official Specification: RFC 3986 (URI Generic Syntax)
Encoding Method: Percent-encoding
- Non-safe characters β
%+ two hexadecimal digits - Hexadecimal represents character's ASCII/UTF-8 code
Character Categories
Unreserved Characters (Never Encoded)
A-Z a-z 0-9 - _ . ~
These are safe in URLs and don't need encoding.
Reserved Characters (Encoded in Specific Contexts)
: / ? # [ ] @ ! $ & ' ( ) * + , ; =
These have special meaning in URLs.
All Other Characters (Always Encoded)
- Spaces
- Special characters: %, <, >, {, }, |, , ^, `
- Non-ASCII characters (Unicode)
- Control characters
Common Encodings Reference
| Character | Description | Encoded | Hex Code |
|---|---|---|---|
| (space) | Space | %20 |
0x20 |
! |
Exclamation | %21 |
0x21 |
" |
Double quote | %22 |
0x22 |
# |
Hash | %23 |
0x23 |
$ |
Dollar | %24 |
0x24 |
% |
Percent | %25 |
0x25 |
& |
Ampersand | %26 |
0x26 |
' |
Single quote | %27 |
0x27 |
( |
Left paren | %28 |
0x28 |
) |
Right paren | %29 |
0x29 |
* |
Asterisk | %2A |
0x2A |
+ |
Plus | %2B |
0x2B |
, |
Comma | %2C |
0x2C |
/ |
Forward slash | %2F |
0x2F |
: |
Colon | %3A |
0x3A |
; |
Semicolon | %3B |
0x3B |
< |
Less than | %3C |
0x3C |
= |
Equals | %3D |
0x3D |
> |
Greater than | %3E |
0x3E |
? |
Question mark | %3F |
0x3F |
@ |
At sign | %40 |
0x40 |
[ |
Left bracket | %5B |
0x5B |
\ |
Backslash | %5C |
0x5C |
] |
Right bracket | %5D |
0x5D |
{ |
Left brace | %7B |
0x7B |
} |
Right brace | %7D |
0x7D |
JavaScript Functions
This tool uses browser's built-in functions:
encodeURIComponent():
- Encodes all characters except:
A-Z a-z 0-9 - _ . ! ~ * ' ( ) - Use for: Query parameter values, form data values
- Most restrictive (safest for parameter values)
encodeURI() (not used by this tool):
- Less restrictive, preserves URL structure characters
- Use for: Encoding entire URLs
- Doesn't encode:
: / ? # [ ] @ ! $ & ' ( ) * + , ; =
decodeURIComponent():
- Reverses
encodeURIComponent() - Converts
%XXback to characters - Throws error for malformed sequences
Browser Compatibility
| Feature | Chrome | Firefox | Safari | Edge |
|---|---|---|---|---|
| encodeURIComponent | β All | β All | β All | β All |
| decodeURIComponent | β All | β All | β All | β All |
| Clipboard API | β 66+ | β 63+ | β 13.1+ | β 79+ |
Universal Support: URL encoding/decoding works in all browsers, even IE6+
Unicode & UTF-8
Non-ASCII Characters:
Character: Γ©
UTF-8 bytes: 0xC3 0xA9
Encoded: %C3%A9
Character: δΈ
UTF-8 bytes: 0xE4 0xB8 0xAD
Encoded: %E4%B8%AD
Character: π
UTF-8 bytes: 0xF0 0x9F 0x9A 0x80
Encoded: %F0%9F%9A%80
How it Works:
- Character converted to UTF-8 bytes
- Each byte encoded as
%XX - Multiple
%XXsequences for multi-byte characters
When to Encode vs Not Encode
β Always Encode
Query Parameter Values:
β
https://example.com/search?q=cats%20%26%20dogs
β https://example.com/search?q=cats & dogs
Form Data Values:
β
name=John%20Doe&email=user%40example.com
β name=John Doe&email=user@example.com
User Input:
β
Any text entered by users before adding to URL
β Trusting user input is safe for URLs
Redirect URIs:
β
redirect_uri=https%3A%2F%2Fmyapp.com%2Fcallback
β redirect_uri=https://myapp.com/callback
β Don't Encode
Complete URLs:
β
https://example.com/path?q=value
β https%3A%2F%2Fexample.com%2Fpath%3Fq%3Dvalue
(Encode only parameter values, not the whole URL)
URL Structure:
β
https://example.com/api/users
β https://example.com%2Fapi%2Fusers
(Don't encode slashes in paths)
Already Encoded Strings:
β
value=Hello%20World (encoded once)
β value=Hello%2520World (double-encoded)
Domain Names:
β
https://example.com
β https%3A%2F%2Fexample.com
Best Practices
For Developers
-
Encode at the Right Layer
- Encode parameter values before building URL
- Don't encode the entire URL string
- Use framework/library encoding functions
-
Validate Before Decoding
- Check if string is properly encoded
- Handle decode errors gracefully
- Validate decoded output
-
Avoid Double Encoding
// Bad const encoded = encodeURIComponent(encodeURIComponent(value)); // Good const encoded = encodeURIComponent(value); -
Use Appropriate Function
encodeURIComponent()for parameter valuesencodeURI()for full URLs (rarely needed)- Don't mix functions
-
Test Edge Cases
- Empty strings
- Special characters:
&,=,%,+ - Unicode characters
- Very long strings
Security Considerations
-
Prevent Injection Attacks
- Always encode user input
- Validate decoded output
- Don't trust external URLs
-
XSS Prevention
- Encoding doesn't prevent XSS
- Still need HTML escaping for display
- Validate and sanitize decoded data
-
Open Redirect Vulnerabilities
// Vulnerable window.location = decodeURIComponent(urlParam); // Better const decoded = decodeURIComponent(urlParam); if (decoded.startsWith('/') && !decoded.startsWith('//')) { window.location = decoded; } -
SSRF Protection
- Validate decoded URLs before making requests
- Whitelist allowed domains
- Don't blindly trust encoded URLs
Troubleshooting
"Error: Invalid input for decoding"
Cause: Malformed percent-encoding sequence.
Examples of Invalid Input:
% (percent without hex digits)
%2 (incomplete hex sequence)
%GH (invalid hex characters)
%20% (trailing percent)
Solutions:
- Check input is properly encoded
- Look for incomplete
%sequences - Verify hex digits are valid (0-9, A-F)
- Remove or complete partial encodings
Plus Signs (+) Decoded as Spaces
Issue: + becomes space when decoded.
Explanation: In application/x-www-form-urlencoded format, + represents space.
Example:
Input: name%2Bemail (should be "name+email")
Output: name+email (correct)
Input: name+email (if from form data)
Output: name email (+ converted to space)
Solution:
- Use
%2Bfor literal plus sign - Understand context (form data vs URL component)
Double Encoding
Symptom: Text encoded twice, showing %25 in output.
Example:
Original: Hello World
First encode: Hello%20World
Second encode: Hello%2520World (wrong!)
How to Fix:
- Decode once:
Hello%2520WorldβHello%20World - Decode again:
Hello%20WorldβHello World
Prevention:
- Check if string is already encoded before encoding
- Use encoding only once per layer
- Track encoding state in your application
Special Characters Not Encoding
Issue: Tool doesn't encode -, _, ., ~, !, *, ', (, ).
Explanation: These are unreserved characters per encodeURIComponent() specification.
This is Correct: These characters are safe in URLs and don't need encoding.
If You Need Different Encoding:
- This follows RFC 3986 standard
- For custom encoding, use server-side libraries
- Most systems expect standard encoding
Spaces as %20 vs +
Context Matters:
- URL Component: Space β
%20 - Form Data: Space β
+or%20(both valid) - This tool uses:
%20(more universal)
Example:
URL: https://example.com/search?q=hello%20world
Form: name=hello+world or name=hello%20world
Both + and %20 work for spaces in query strings, but %20 is more consistent.
Code Examples
JavaScript
Basic Encoding/Decoding:
// Encode
const text = "Hello World!";
const encoded = encodeURIComponent(text);
console.log(encoded); // Hello%20World%21
// Decode
const decoded = decodeURIComponent(encoded);
console.log(decoded); // Hello World!
Building URLs with Parameters:
const baseUrl = "https://api.example.com/search";
const params = {
q: "cats & dogs",
limit: 10,
filter: "status=active"
};
const queryString = Object.entries(params)
.map(([key, value]) =>
`${encodeURIComponent(key)}=${encodeURIComponent(value)}`
)
.join('&');
const fullUrl = `${baseUrl}?${queryString}`;
// https://api.example.com/search?q=cats%20%26%20dogs&limit=10&filter=status%3Dactive
Using URLSearchParams (Modern Approach):
const params = new URLSearchParams();
params.append('q', 'cats & dogs');
params.append('limit', '10');
params.append('filter', 'status=active');
const fullUrl = `https://api.example.com/search?${params}`;
// Automatically encodes values
Python
from urllib.parse import quote, unquote
# Encode
text = "Hello World!"
encoded = quote(text)
print(encoded) # Hello%20World%21
# Decode
decoded = unquote(encoded)
print(decoded) # Hello World!
# Building URLs
import urllib.parse
params = {
'q': 'cats & dogs',
'limit': 10,
'filter': 'status=active'
}
query_string = urllib.parse.urlencode(params)
full_url = f"https://api.example.com/search?{query_string}"
PHP
// Encode
$text = "Hello World!";
$encoded = urlencode($text);
echo $encoded; // Hello+World%21
// Or use rawurlencode (equivalent to encodeURIComponent)
$encoded = rawurlencode($text);
echo $encoded; // Hello%20World%21
// Decode
$decoded = urldecode($encoded);
echo $decoded; // Hello World!
// Building query strings
$params = [
'q' => 'cats & dogs',
'limit' => 10,
'filter' => 'status=active'
];
$query_string = http_build_query($params);
$full_url = "https://api.example.com/search?" . $query_string;
cURL
# Encode in command line (using --data-urlencode)
curl -G "https://api.example.com/search" \
--data-urlencode "q=cats & dogs" \
--data-urlencode "filter=status=active"
# Or manually encode
curl "https://api.example.com/search?q=cats%20%26%20dogs&filter=status%3Dactive"
Frequently Asked Questions
1. What's the difference between encoding the whole URL vs just parameters?
Don't encode the whole URL:
β Wrong: https%3A%2F%2Fexample.com%2Fsearch%3Fq%3Dcats
This breaks the URL structure.
Encode only parameter values:
β
Correct: https://example.com/search?q=cats%20%26%20dogs
Rule: Encode only the values of query parameters, not the URL structure (protocol, domain, path, ?, &, =).
2. Why does my space become + instead of %20?
Both are valid for spaces in query strings:
%20= Standard URL encoding (RFC 3986)+= Form encoding (application/x-www-form-urlencoded)
This tool uses %20 because:
- More universal
- Works in all contexts
- Required for non-query-string URLs
Both work in query strings:
https://example.com?q=hello%20world β
https://example.com?q=hello+world β
3. Can I encode emojis and special Unicode characters?
Yes! The tool encodes all Unicode characters.
Examples:
π β %F0%9F%98%80
δΈζ β %E4%B8%AD%E6%96%87
cafΓ© β caf%C3%A9
How it works:
- Character β UTF-8 bytes
- Each byte β
%XXformat - Concatenate all
%XXsequences
4. Do I need to encode forward slashes (/) in paths?
It depends on context:
In URL paths (NO):
β
https://example.com/api/users/123
β https://example.com/api%2Fusers%2F123
In parameter values (YES):
β
https://example.com/api?path=%2Fhome%2Fuser%2Fdocuments
β https://example.com/api?path=/home/user/documents
Rule: Don't encode structural slashes, DO encode slashes in data.
5. What happens if I encode an already-encoded string?
You get double-encoding:
Original: Hello World
First encode: Hello%20World
Second encode: Hello%2520World
The % itself gets encoded as %25.
How to fix: Decode once to get back to first encode, or decode twice to get original.
Prevention: Track encoding state, don't encode twice.
6. Why doesn't the tool encode hyphens (-) or underscores (_)?
These are "unreserved" characters per RFC 3986 and don't need encoding.
Unreserved characters (never need encoding):
A-Z a-z 0-9 - _ . ~
These are safe in URLs and encoding them is unnecessary (though not harmful).
7. Can I use this for encoding passwords?
Not recommended for security:
- URL encoding β encryption
- Encoded passwords are easily decoded
- URLs may be logged (including parameters)
Better approaches:
- Use HTTPS (encrypts entire request)
- Send passwords in request body (POST)
- Use proper authentication tokens
- Never put passwords in URLs
If you must: Use POST with form body or JSON, over HTTPS only.
8. How do I encode an entire JSON object for a URL parameter?
Steps:
- Convert JSON to string
- Encode the string
Example:
const data = {
name: "John Doe",
email: "john@example.com",
roles: ["admin", "user"]
};
// Step 1: JSON to string
const jsonString = JSON.stringify(data);
// {"name":"John Doe","email":"john@example.com","roles":["admin","user"]}
// Step 2: Encode
const encoded = encodeURIComponent(jsonString);
// %7B%22name%22%3A%22John%20Doe%22%2C%22email%22%3A%22john%40example.com%22%2C%22roles%22%3A%5B%22admin%22%2C%22user%22%5D%7D
// Use in URL
const url = `https://api.example.com/process?data=${encoded}`;
Decoding back:
const decoded = decodeURIComponent(encoded);
const object = JSON.parse(decoded);
9. What's the maximum length of an encoded URL?
Practical Limits:
- Browsers: 2,000 characters (IE), most support 10,000+
- Servers: Often limit to 8,192 characters
- Recommendation: Keep under 2,000 for compatibility
If URL too long:
- Use POST instead of GET
- Send data in request body
- Abbreviate or compress data
- Use URL shortening services
10. How do I test if a string is already URL-encoded?
No perfect way, but heuristics:
function isEncoded(str) {
try {
// If decoding changes it, it was encoded
return str !== decodeURIComponent(str);
} catch (e) {
// Decoding failed, probably not encoded
return false;
}
}
// Examples
isEncoded("Hello%20World"); // true
isEncoded("Hello World"); // false
isEncoded("100%25"); // true
Not 100% reliable because:
- Some encoded strings decode to themselves
- Some plain text might look encoded
Best practice: Track encoding in your code rather than detecting it.
Conclusion
The URL Encoder / Decoder is an essential utility for web development, making it easy to work with URLs containing special characters. Whether you're building APIs, debugging web requests, or preparing data for transmission, this tool ensures your URLs are properly formatted and compliant with web standards.
Key Takeaways
β
Automatic transformation saves time with real-time encoding/decoding
β
Bidirectional allows easy switching between modes
β
Copy functionality streamlines your workflow
β
Client-side processing ensures privacy and speed
β
Standards-compliant follows RFC 3986 specification
β
Unicode support handles international characters and emojis
Quick Reference
| Task | Steps |
|---|---|
| Encode text | Select Encode β Type text β Copy result |
| Decode URL | Select Decode β Paste encoded URL β Copy result |
| Switch modes | Click swap button (β) to exchange mode and values |
| Clear fields | Click Clear button to reset |
Start encoding and decoding URLs with confidence and ease! πβ¨