URL Encode

Percent encode text so it is safe to drop into a URL or query string. Use component mode for a single value or full mode to keep the structure of a complete URL.

0 characters

0 characters

About URL Encode

This tool performs percent-encoding[1], a mechanism for encoding information in a Uniform Resource Identifier[2] (URI) under specific circumstances. Also known as URL encoding, this process ensures that text data can be safely transmitted as part of a URL, particularly within the path or query string components. It works by replacing characters that are either syntactically significant (reserved characters) or not part of the allowed US-ASCII[3] character set with a percent sign (%) followed by two hexadecimal digits that represent the byte value of the character.

The definitive standard for URIs, RFC 3986[10], formally defines percent-encoding and categorizes ASCII characters into two sets: reserved and unreserved. Unreserved characters (A-Z, a-z, 0-9, and the symbols -, _, ., ~) can be used literally in a URI without encoding. Reserved characters (such as !, #, $, &, ', (, ), *, +,, /, :, ;, =, ?, @, [, and ]) have special meaning within the URI syntax, like separating the scheme from the authority or the path from the query. If these characters need to appear as literal data within a URI component, they must be percent-encoded to prevent misinterpretation by parsers.

The history of URI syntax reflects the evolution of the internet itself. The initial concepts were laid out by Tim Berners-Lee[4] in the early 1990s. The first formal specification, RFC 1738[11] (December 1994), defined the syntax for Uniform Resource Locators (URLs) and described the encoding for unsafe characters. This was later superseded by RFC 2396[12] (August 1998), which generalized the syntax for URIs. The current standard, RFC 3986[10] (January 2005), refined these rules, clarified ambiguities, and officially established the term 'percent-encoding' to describe the process.

A critical aspect of modern percent-encoding is its handling of non-ASCII characters through the Unicode[5] standard, specifically using the UTF-8[6] character encoding. To encode a character outside the ASCII range (e.g., 'é' or 'π'), the character is first represented as a sequence of one to four bytes according to UTF-8 rules. Then, each byte in that sequence is percent-encoded. This approach enables internationalization[7] by allowing virtually any character from any language to be represented in a URL, albeit at the cost of increased string length. This process is distinct from older, system-specific code page encodings and provides a consistent, universal standard for web interoperability.

Correctly applying percent-encoding is also a matter of security. Improper handling of encoding and decoding can introduce serious vulnerabilities. For example, if user-supplied data is not correctly encoded before being embedded in a URL that is later processed, it could lead to injection attacks. A malicious string might be crafted to exploit how a server-side application decodes the URL, potentially leading to Cross-Site Scripting (XSS)[8] or even SQL injection[9] if the decoded data is passed to a database query without further sanitization. Therefore, consistently and correctly encoding data for its specific context in a URI is a fundamental practice for secure web development.

How to Use

  1. Enter or paste the raw, unencoded text into the primary input text area.
  2. The tool automatically processes your input in real-time.
  3. The resulting percent-encoded string will appear instantly in the output field below.
  4. Use the 'Copy' button to transfer the encoded string to your clipboard for use in a URL path, query parameter, or other URI component.
  5. Modify the input text at any time to generate a new encoded version.
  6. The encoding is based on the RFC 3986[10] standard, suitable for all parts of a URI.

Frequently Asked Questions

What is the difference between URL encoding and percent-encoding?

They refer to the same process. 'URL encoding' is the common, historical term. 'Percent-encoding[1]' is the official, standardized term defined in the current URI specification, RFC 3986[10].

Why is a space encoded as %20 instead of a plus sign (+)?

The plus sign (+) for a space is a special convention from an older standard used only for the `application/x-www-form-urlencoded` MIME type, typically seen in HTML form submissions. For all other parts of a URL, including the path and query string components, the standard percent-encoding for a space character (ASCII 0x20) is `%20`, as specified by RFC 3986[10].

Which characters are 'unreserved' and do not require encoding?

According to RFC 3986[10], the unreserved characters are the uppercase and lowercase letters A-Z a-z, the digits 0-9, and the symbols hyphen (-), period (.), underscore (_), and tilde (~). These characters have no special meaning and can always be used literally.

What are the 'reserved' characters and why must they be encoded?

The reserved characters are `! * ' ( ) ; : @ & = + $ , / ? # [ ]`. They act as delimiters for different components of a URI[2]. If you want to use one of these characters as part of the actual data in a path segment or query value, you must percent-encode it to prevent it from being misinterpreted by a URI parser.

How are non-ASCII characters like '你好' or 'é' encoded?

They are first converted into a sequence of bytes using the UTF-8[6] encoding standard. Then, each byte in that sequence is represented in the `%hh` hexadecimal format. For example, 'é' is `C3 A9` in UTF-8, so it becomes `%C3%A9`. '你好' becomes `%E4%BD%A0%E5%A5%BD`.

What is the difference between JavaScript's encodeURI() and encodeURIComponent()?

`encodeURIComponent()` is more aggressive and should be used for encoding a single component of a URI, like a query parameter value. It encodes reserved characters like `/`, `?`, and `&`. `encodeURI()` is meant for encoding a full URI and therefore does not encode those reserved characters, assuming they are part of the URI's structure.

Can URL encoding be reversed?

Yes, percent-encoding is a deterministic and fully reversible process. The corresponding process, percent-decoding, converts each `%hh` sequence back into its original character byte, allowing the original data to be reconstructed perfectly.

What happens if you 'double encode' a string?

Double encoding means applying percent-encoding to a string that is already encoded. This can cause data corruption and application errors. For example, encoding the '%' character gives `%25`. If you encode `%25`, you get `%2525`. If a server decodes this twice, it gets back `%25`, not the original '%'. This behavior can sometimes be exploited in security attacks.

Sources (12)
  1. Wikipedia: Percent-encoding
  2. Wikipedia: Uniform Resource Identifier (URI)
  3. Wikipedia: ASCII
  4. Wikipedia: Tim Berners-Lee
  5. Wikipedia: Unicode
  6. Wikipedia: UTF-8
  7. Wikipedia: Internationalization and localization
  8. Wikipedia: Cross-Site Scripting (XSS)
  9. Wikipedia: SQL injection
  10. IETF RFC 3986: Uniform Resource Identifier (URI): Generic Syntax
  11. IETF RFC 1738: Uniform Resource Locators (URL) (Obsolete)
  12. IETF RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax (Obsolete)

About Matt George

I'm Matt George, a software engineer in the startup space. I run my own shop building software for early-stage founders, and I love making free tools and experiences that people actually use. Enjoy using URL Encode!

More Free Tools