URL Encoder/Decoder
Encode or decode URLs and query parameter values, with a choice between full-URI and query-component encoding.
What is URL Encoding (Percent-Encoding) and When Should You Use It?
Quick Answer: URL encoding (also known as percent-encoding) converts non-ASCII and reserved characters in web addresses into hexadecimal sequences prefixed with a percent sign (e.g., spaces become %20). Defined by RFC 3986, it prevents transmission errors and syntax confusion across web browsers, web servers, and APIs. Use Query Component mode for individual parameter values and Full URI mode when formatting a complete address.
Web addresses strictly permit only ASCII characters from a specific subset. When URLs contain international characters, spaces, or reserved syntax delimiters like ampersands (&) and question marks (?), those characters must be percent-encoded to prevent parsers from misinterpreting parameter boundaries.
RFC 3986 Character Class Reference
| Character Category | Characters Included | Full URI (encodeURI) | Query Component (encodeURIComponent) | Functional Role |
|---|---|---|---|---|
| Unreserved | A-Z, a-z, 0-9, -, _, ., ~ |
Preserved (Not encoded) | Preserved (Not encoded) | Standard data characters safe in all URI positions |
| Reserved (Gen-delims) | :, /, ?, #, [, ], @ |
Preserved (Not encoded) | Encoded (e.g. / -> %2F) |
Separates URI components (scheme, host, path, query, fragment) |
| Sub-delimiters | !, $, &, ', (, ), *, +, ,, ;, = |
Preserved (Not encoded) | Encoded (e.g. & -> %26) |
Separates query parameters and subcomponents |
| Whitespace & Control | Space, Tab, Line breaks | Encoded (%20) |
Encoded (%20) |
Unsafe in raw URLs; causes parser termination |
| Unicode / Emojis | Non-ASCII code points (e.g., é, ✓, ☕) |
Encoded (UTF-8 bytes) | Encoded (UTF-8 bytes) | Multi-byte UTF-8 sequences converted to percent-triplets |
The Critical Distinction: encodeURI vs encodeURIComponent
Modern web runtimes provide two native JavaScript functions for URL encoding with fundamentally different scopes and responsibilities:
- encodeURI(uri): Intended exclusively for complete, well-formed web addresses (such as
https://example.com/search?q=hello world). It escapes non-ASCII characters and whitespace (converting spaces to%20), but deliberately preserves protocol delimiters, slashes, question marks, hashes, and parameter delimiters (:,/,?,#,&,=). UsingencodeURI()on individual query values will cause parsing bugs if the value itself contains an ampersand or question mark. - encodeURIComponent(component): Intended for isolated data payloads destined to reside inside a specific query parameter value, form field, or dynamic path variable. It aggressively escapes structural delimiters including
/,:,?,&,=, and+. For example, if a search query containsTom & Jerry,encodeURIComponent()transforms it intoTom%20%26%20Jerry, ensuring the ampersand is treated as literal data rather than a secondary parameter split.
Mechanics of UTF-8 Multi-Byte Serialization
When an international character, mathematical symbol, or emoji enters a URL, the encoding engine does not operate on Unicode code points directly. Instead, it follows a strict two-phase transformation:
- UTF-8 Byte Generation: The character is converted into its variable-length UTF-8 binary representation (between 1 and 4 bytes). For instance, the ASCII character
Ais 1 byte (0x41), the Latin characteréis 2 bytes (0xC3 0xA9), the Devanagari characterॐis 3 bytes (0xE0 0xA5 0x90), and the emoji🚀is 4 bytes (0xF0 0x9F 0x9A 0x80). - Percent-Hex Formatting: Each individual byte is serialized as a literal percent symbol (
%) followed by two uppercase hexadecimal digits. Thus,ébecomes%C3%A9, and🚀becomes%F0%9F%9A%80.
When decoding, the parser must read the complete multi-byte sequence before reconstructing the Unicode character. If a percent-encoded string is truncated prematurely (for example, receiving %F0%9F without the trailing two bytes), browsers throw a URIError: malformed URI sequence.
Form URL Encoding (+ Signs) vs Standard RFC 3986 Percent Encoding
A frequent source of developer confusion is the difference between percent-encoding in standard URIs and the older application/x-www-form-urlencoded format used by HTML forms:
- RFC 3986 (Modern Web Standard): Spaces are strictly encoded as
%20. The plus sign (+) is an unreserved sub-delimiter that remains a literal plus unless explicitly escaped to%2B. - W3C Form URL Encoding: Standardized in HTML 4.01 and WHATWG URL specs, spaces in form submissions are converted to plus signs (
+). In this context, an actual plus symbol must be escaped as%2Bto avoid being parsed as a space upon arrival at the server.
Our tool provides an interactive Space Encoding dropdown so you can conveniently toggle between RFC 3986 (%20) and form-encoded (+) outputs depending on whether you are building modern REST API calls or legacy form payloads.
Common Failure Modes in Production Pipelines
Mismanaged URL encoding causes persistent production incidents across web applications:
- Double Encoding (%25): If a string that has already been encoded (such as
hello%20world) is passed through an encoder a second time, the percent sign itself is escaped to%25, producinghello%2520world. Decoders will unescape the string tohello%20worldinstead of the original plaintext. - Parameter Splitting and Injection: When user-supplied query strings are concatenated without escaping, malicious inputs containing
&admin=trueor&role=superusercan hijack backend authorization filters. - OAuth Redirect URI Mismatches: In OAuth 2.0 authorization flows, the
redirect_uriparameter must be component-encoded. If the provider expectshttps%3A%2F%2Fapp.io%2Fcallbackbut receives an unescaped URL, the authorization server rejects the request with an invalid redirect URI error.
Security Considerations: Open Redirects, CRLF Injection, and SSRF
URL encoding plays an indispensable role in securing web endpoints against transport-level exploitation:
- CRLF Injection: HTTP headers and protocols interpret carriage return (
%0D) and line feed (%0A) as message boundary delimiters. Failing to encode these characters allows attackers to inject arbitrary HTTP response headers or split response bodies (HTTP Response Splitting). - Open Redirects: Applications that accept an unescaped return URL parameter (e.g.
/login?returnUrl=https://attacker.com) must validate and decode targets strictly against an allowlist of approved domains. - Server-Side Request Forgery (SSRF): When backend microservices fetch resources based on decoded query parameters, attackers often use encoded alternate representations (such as IPv6 brackets, hex IP notation, or octal IP strings) to bypass perimeter firewall filters and access internal cloud metadata services (e.g.
169.254.169.254).
Cross-Platform Implementation Guide
Authoritative cheat sheet for encoding and decoding URLs across modern programming ecosystems:
| Environment | Component Encode | Component Decode | Full URI Handling |
|---|---|---|---|
| JavaScript (ES6+) | encodeURIComponent(str) |
decodeURIComponent(str) |
encodeURI(str) / decodeURI(str) |
| Python 3 | urllib.parse.quote(str, safe='') |
urllib.parse.unquote(str) |
urllib.parse.quote(str) |
| Go (Golang) | url.QueryEscape(str) |
url.QueryUnescape(str) |
url.PathEscape(str) |
| PHP | rawurlencode($str) |
rawurldecode($str) |
urlencode($str) (uses +) |
| Java | URLEncoder.encode(str, StandardCharsets.UTF_8) |
URLDecoder.decode(str, StandardCharsets.UTF_8) |
URI.create(str).toASCIIString() |
| C# / .NET | Uri.EscapeDataString(str) |
Uri.UnescapeDataString(str) |
Uri.EscapeUriString(str) |
Client-Side Zero-Trust Architecture
Security and data confidentiality are critical when handling URLs that contain sensitive access tokens, OAuth authorization codes, session IDs, or personally identifiable query parameters. Utility369 executes all URL transformations, regular expression splits, and parameter extraction algorithms entirely within your web browser's local sandbox memory. No URL text or query data is transmitted across the network, stored on remote databases, or logged in server telemetry.
Frequently Asked Questions
What is the difference between Query Component and Full URI encoding?
Query Component mode (encodeURIComponent) encodes all punctuation except unreserved characters (- _ . ! ~ * ' ( )), safely escaping structural characters like / : ? & =. Full URI mode (encodeURI) preserves structural delimiters because a complete URI uses them to delineate protocol, host, path, and query parts.
Why do query parameters fail when they contain an unescaped ampersand or equals sign?
In standard URL parsing, the ampersand (&) separates distinct key-value pairs, and the equals sign (=) assigns values to keys. When raw & or = appears inside a value without component encoding (%26 or %3D), the parser breaks the value into multiple truncated parameters.
Why do some URLs use plus signs (+) instead of %20 for spaces?
RFC 3986 specifies %20 for spaces in standard URIs. However, the application/x-www-form-urlencoded format traditionally used by HTML form submissions encodes spaces as plus (+) signs. This tool supports decoding plus signs into literal spaces via a dedicated toggle.
What causes a malformed URI sequence error during URL decoding?
A malformed URI error occurs when a percent symbol (%) is not followed by two valid hexadecimal digits, or when percent-encoded bytes form an incomplete UTF-8 byte sequence due to string truncation or corruption.
Should I use encodeURI or encodeURIComponent when sending data via API?
When appending query parameter values or dynamic path segments in an API call, always use encodeURIComponent on each individual parameter. Only use encodeURI when you need to escape spaces in a complete pre-constructed URL without altering existing query strings.
Is my URL or sensitive token data transmitted to any external server?
No. All URL encoding, decoding, and query parameter parsing run entirely on your device using client-side JavaScript. No URL strings, session IDs, or private keys are ever uploaded or logged.
How does UTF-8 multi-byte encoding translate into percent-encoded sequences?
Characters outside the ASCII range are first converted into their variable-length UTF-8 binary bytes (1 to 4 bytes). Each resulting byte is then converted to its two-digit uppercase hexadecimal representation preceded by a percent symbol, such as %C3%A9 for the letter e with acute accent.
Can URL encoding prevent Cross-Site Scripting (XSS) and injection vulnerabilities?
URL encoding ensures safe transport through web addresses and query strings, but it is not a substitute for HTML entity escaping or database parameterization. When reflecting decoded values into an HTML document or SQL query, proper context-aware sanitization remains mandatory.
Why are characters like exclamation marks and tildes sometimes left unencoded?
RFC 3986 defines tilde (~), hyphen (-), underscore (_), and period (.) as unreserved characters that never require encoding. While RFC 2396 historically treated exclamation marks and asterisks as reserved sub-delimiters, JavaScript encodeURIComponent preserves them by default according to legacy ECMAScript standards.
How should nested URLs or redirect URLs inside query strings be encoded?
When passing a complete URL as a parameter value inside another URL (such as an OAuth redirect_uri or proxy target), the nested URL must be fully encoded using encodeURIComponent. This ensures slashes, colons, and question marks inside the nested URL are not mistaken for parts of the outer URL.