URL Encoder / Decoder
Encode and decode URLs using percent-encoding (RFC 3986). Convert special characters to %XX format for safe use in URLs, query strings, and API parameters. Supports both encodeURIComponent (parameters) and encodeURI (full URLs). Handles Unicode and emoji.
Key Facts
- Standard: Percent-encoding is defined in RFC 3986 (Uniform Resource Identifier). Characters are replaced with % followed by two hex digits representing their byte value
- Safe Characters: Letters (A-Z, a-z), digits (0-9), and
-_.~are never encoded. Everything else is converted to %XX sequences - encodeURIComponent: Encodes everything except
A-Za-z0-9 - _ . ~ ! ' ( ) *. Use for query parameter values where &, =, and / must be escaped - encodeURI: Preserves URL structural characters (
: / ? # [ ] @ ! $ & ' ( ) * + , ; =). Use for encoding a complete URL while keeping its structure intact - Unicode: Non-ASCII characters are first converted to UTF-8 bytes, then each byte is percent-encoded. For example,
Γ©β%C3%A9(two UTF-8 bytes)
encodeURI vs encodeURIComponent β When to Use Each
- encodeURIComponent: Use when encoding a single query parameter value, form field value, or any data that will be inserted into a URL. Encodes & = / ? # so they do not break URL structure
- encodeURI: Use when encoding a complete URL that should remain navigable. Preserves :// / ? & = # so the URL structure stays intact
- Common mistake: Using encodeURI on a parameter value like
q=hello&worldwill NOT encode the &, breaking the query string. Use encodeURIComponent instead - Double encoding: Never encode an already-encoded string.
%20becomes%2520which is a common bug. Our tool detects already-encoded input
Common URL Encodings Reference
- Space:
%20(or+in form data). The most common encoding - & (ampersand):
%26β critical to encode in parameter values to avoid splitting the query string - = (equals):
%3Dβ must encode in values to avoid being interpreted as a key-value separator - ? (question mark):
%3Fβ encode to prevent starting a new query string - # (hash):
%23β must encode or the browser treats everything after as a fragment - / (slash):
%2Fβ encode in parameter values; leave intact in URL paths - + (plus):
%2Bβ important because + means space in form data (application/x-www-form-urlencoded)
Frequently Asked Questions
What is URL encoding?
URL encoding (percent-encoding) converts characters that are not allowed or have special meaning in URLs into a safe format. Special characters are replaced with a percent sign followed by their hexadecimal ASCII value β for example, a space becomes %20 and an ampersand becomes %26. This is defined in RFC 3986.
What is the difference between encodeURI and encodeURIComponent?
encodeURI encodes a complete URL while preserving structural characters like :, /, ?, #, and & that are part of the URL syntax. encodeURIComponent encodes everything except unreserved characters β it is used for encoding individual query parameter values where characters like & and = must be escaped to avoid breaking the URL structure.
When should I URL encode data?
URL encode data when passing user input as query parameters, embedding special characters in URLs, building API request URLs, constructing form data for application/x-www-form-urlencoded submissions, and when handling filenames or paths that contain spaces or non-ASCII characters.
Does URL encoding handle Unicode and emoji?
Yes. JavaScript's encodeURIComponent first converts Unicode characters to their UTF-8 byte representation, then percent-encodes each byte. For example, the emoji π becomes %F0%9F%94%92 (four UTF-8 bytes, each percent-encoded). Accented characters like Γ© become %C3%A9 (two UTF-8 bytes).
What is double encoding and how do I avoid it?
Double encoding happens when you encode an already-encoded string. For example, %20 (encoded space) becomes %2520 when encoded again. This causes the server to see a literal %20 instead of a space. Always encode raw data only once, and decode fully before re-encoding if needed.