Developer3 min read
URL Encode & Decode - How to Safely Pass Data in URLs
URLs can only contain a limited set of ASCII characters. When you need to include spaces, Unicode, or special characters in a URL, they must be percent-encoded. URL encoding replaces unsafe characters with %XX hex codes - like %20 for a space or%3F for a question mark.
What Gets Encoded?
Characters that are encoded in URLs:
- Reserved characters -
: / ? # [ ] @ ! $ & ' ( ) * + , ; =- have special meaning in URLs - Unsafe characters - spaces, quotes, angle brackets, curly braces
- Non-ASCII characters - Unicode like Chinese, Japanese, emoji - first UTF-8 encoded, then percent-encoded
Characters that are not encoded: letters (A-Z, a-z), digits (0-9), and - _ . ~
Common Encoded Characters
- Space =
%20(or+in query strings) &=%26==%3D?=%3F/=%2F#=%23
When to URL-Encode
- Query parameters - encoding values in
?key=value - API requests - passing JSON or special characters as URL parameters
- Redirect URLs - embedding one URL inside another
- OAuth flows - state and redirect_uri parameters
- Internationalization - any URL containing non-ASCII characters
URL Encode vs. HTML Entities
These are different encoding schemes for different contexts:
- URL encoding - for URLs:
&becomes%26. Use URL Encoder. - HTML entities - for HTML content:
&becomes&. Use HTML Entity Encoder.
Using the wrong encoding is a common source of bugs.
Free Online URL Encoder/Decoder
Use SnapSum URL Encoder/Decoder - encode or decode URLs instantly in your browser. No server processing, no data retention.
- Encode: paste plain text and get URL-encoded string
- Decode: paste encoded string and get readable text
- Handles Unicode and multi-byte characters correctly
- Live encoding as you type
Step-by-Step: URL Encode/Decode
- Open URL Encoder/Decoder.
- Paste your text or encoded URL.
- Click "Encode" or "Decode."
- Copy the result.
Developer Tip: encodeURIComponent vs. encodeURI
In JavaScript:
encodeURI()- encodes a full URL, but preserves: / ? # & =(so the URL structure stays intact)encodeURIComponent()- encodes a URL component (like a query value), encoding everything including: / ? # & =
Use encodeURIComponent for query parameter values, encodeURI for full URLs.