What Is URL Encoding?
URL encoding (also called percent encoding) is the process of converting characters in a URL into a format that can be safely transmitted over the internet. Characters that have special meanings in URLs — like spaces, ampersands, question marks, and slashes — must be converted to percent-encoded sequences to avoid breaking the URL structure.
Encode and decode URLs instantly with WritePadPro's URL Encoder & Decoder — paste any text and get the percent-encoded version, or paste an encoded URL to decode it back to readable text.
The URL https://example.com/search?q=hello world&lang=en is broken because of the space in "hello world": spaces are not allowed in URLs. The & that separates the q and lang parameters is structure, so it stays as is. The correctly encoded version is: https://example.com/search?q=hello%20world&lang=en where %20 represents a space character.
URL encoding is defined by RFC 3986 (Uniform Resource Identifier: Generic Syntax), published by the Internet Engineering Task Force (IETF). Every web browser, server, and HTTP client implements this standard to ensure URLs work consistently across the entire internet.
Reserved vs Unreserved Characters
For URL purposes, characters fall into three groups. RFC 3986 defines the unreserved and reserved sets; everything else must be percent-encoded.
Unreserved Characters (Never Encoded)
These characters are safe in any position within a URL and should never be percent-encoded:
| Category | Characters |
|---|---|
| Uppercase letters | A B C D E F G H I J K L M N O P Q R S T U V W X Y Z |
| Lowercase letters | a b c d e f g h i j k l m n o p q r s t u v w x y z |
| Digits | 0 1 2 3 4 5 6 7 8 9 |
| Special unreserved | - _ . ~ |
Total: 66 characters that pass through URLs unchanged.
Reserved Characters (Encode When Used as Data)
These characters have special structural meaning in URLs. They must be percent-encoded when used as literal data (not structure):
| Character | Encoded | URL Meaning |
|---|---|---|
| : | %3A | Separates scheme from authority (https://) |
| / | %2F | Path separator (/blog/post) |
| ? | %3F | Starts query string (/search?q=term) |
| # | %23 | Fragment identifier (page#section) |
| & | %26 | Query parameter separator (a=1&b=2) |
| = | %3D | Key-value separator (key=value) |
| + | %2B | Space in some form encodings |
| @ | %40 | User info separator (user@host) |
| ! | %21 | Sub-delimiter |
| $ | %24 | Sub-delimiter |
| ' | %27 | Sub-delimiter |
| ( | %28 | Sub-delimiter |
| ) | %29 | Sub-delimiter |
| * | %2A | Sub-delimiter |
| , | %2C | Sub-delimiter |
| ; | %3B | Parameter separator (legacy) |
Unsafe Characters (Always Encoded)
Characters outside both sets — spaces, control characters, the ASCII symbols below, and all characters above 127 — must always be encoded:
| Character | Encoded | Notes |
|---|---|---|
| Space | %20 (or +) | Most common encoding; + is allowed in query strings only |
| < | %3C | HTML tag opener — security risk if unencoded |
| > | %3E | HTML tag closer |
| " | %22 | Attribute delimiter |
| { | %7B | Not allowed in URLs |
| } | %7D | Not allowed in URLs |
| | | %7C | Not allowed in URLs |
| \ | %5C | Not allowed in URLs |
| ^ | %5E | Not allowed in URLs |
| ` | %60 | Not allowed in URLs |
For encoding characters in HTML context instead of URLs, see the HTML Encoder & Decoder. For encoding binary data as text, see our Base64 Guide.
How Percent Encoding Works
The percent encoding mechanism is simple: replace the character with a percent sign (%) followed by its two-digit hexadecimal ASCII value.
Single-Byte Characters (ASCII 0-127)
Space (ASCII 32, hex 20) → %20
Ampersand (ASCII 38, hex 26) → %26
Equals (ASCII 61, hex 3D) → %3D
At sign (ASCII 64, hex 40) → %40
Multi-Byte Characters (UTF-8)
Non-ASCII characters (accented letters, CJK characters, emoji) are first converted to their UTF-8 byte sequence, then each byte is percent-encoded individually.
The German umlaut ü (Unicode U+00FC) encodes to UTF-8 as two bytes: C3 BC. In a URL: %C3%BC
The Chinese character 中 (Unicode U+4E2D) encodes to UTF-8 as three bytes: E4 B8 AD. In a URL: %E4%B8%AD
The emoji 🔥 (Unicode U+1F525) encodes to UTF-8 as four bytes: F0 9F 94 A5. In a URL: %F0%9F%94%A5
Modern browsers display these as Internationalized Resource Identifiers (IRIs) in the address bar — showing the readable characters rather than the encoded bytes — but transmit the percent-encoded version over HTTP.
encodeURI vs encodeURIComponent
JavaScript provides two URL encoding functions. Using the wrong one is a common source of bugs.
encodeURI()
Encodes a complete URI. Does NOT encode characters that have structural meaning in URLs: : / ? # @ ! $ & ' ( ) * + , ; = (it does encode [ and ])
Use for: encoding an entire URL where the structure (scheme, host, path, query) should remain intact.
encodeURI("https://example.com/path/to page?q=hello world")
// → "https://example.com/path/to%20page?q=hello%20world"
// Note: : / ? are NOT encoded (structure preserved)encodeURIComponent()
Encodes a URI component (a single value). DOES encode most reserved characters, including : / ? # & = +. It leaves ! ' ( ) * unencoded.
Use for: encoding a single query parameter value, path segment, or any piece of data that will be inserted into a URL.
encodeURIComponent("hello world & goodbye")
// → "hello%20world%20%26%20goodbye"
// Note: & IS encoded (it's data, not structure)The Critical Difference
| Scenario | Correct Function | Why |
|---|---|---|
| Encoding a full URL | encodeURI() | Preserves :// / ? = & structure |
| Encoding a query parameter value | encodeURIComponent() | Encodes & = so they become data, not structure |
| Encoding a path segment | encodeURIComponent() | Encodes / so it becomes data, not a path separator |
| Encoding form data | encodeURIComponent() | All special characters in values must be encoded |
The Common Bug
Using encodeURI() on a query value that contains &:
// WRONG: & is not encoded — breaks the query string
encodeURI("rock & roll") → "rock%20&%20roll"
// The & is interpreted as a parameter separator!
// RIGHT: & is encoded as %26
encodeURIComponent("rock & roll") → "rock%20%26%20roll"For related encoding in HTML, see our HTML Entities Guide. For URL structures in SEO, see the Meta Tags Guide.
Common Use Cases
Query String Parameters
When building URLs with dynamic values, every parameter value must be encoded:
const query = encodeURIComponent(userInput);
const url = `https://api.example.com/search?q=${query}`;Without encoding, a user input like "price < 100" would break the URL (the < creates an invalid URL character).
Form Data Submission
HTML forms with method="GET" encode form values into the URL query string. The browser handles encoding automatically using the application/x-www-form-urlencoded content type, where spaces become + instead of %20.
API Requests
RESTful APIs that accept parameters in URLs require proper encoding. An API call searching for "C++ programming" must encode the ++ to %2B%2B, or the server receives "C programming" (pluses decoded as spaces).
Internationalized URLs
Domain names with non-ASCII characters use Punycode (a different encoding). Path and query components use UTF-8 percent encoding. The URL for a Japanese page might look like /blog/%E6%97%A5%E6%9C%AC%E8%AA%9E in transmission but display as /blog/日本語 in the browser. For embedding binary data as text, use the Base64 Encoder & Decoder. Also see our Text Case Guide for URL slug formatting conventions (kebab-case).
Using WritePadPro's URL Encoder & Decoder
WritePadPro's URL Encoder & Decoder converts between plain text and percent-encoded text instantly.
Step 1: Open the Tool
Navigate to the URL Encoder & Decoder. You will see an input area with Encode and Decode options, a choice between Component and Full URL, and a "+ for spaces" checkbox.
Step 2: Encode Text
Paste any text — a URL parameter value, a file path, a search query, or any string with special characters. Choose Encode; the output updates as you type. Component mode (encodeURIComponent) encodes reserved characters such as & = / ? along with spaces and non-ASCII characters. Full URL mode (encodeURI) keeps the URL structure intact. Tick "+ for spaces" for HTML form encoding.
Step 3: Decode URL-Encoded Text
Paste a percent-encoded string (e.g., hello%20world%26goodbye). Choose Decode. In Component mode, the tool converts every %XX sequence back to its original character. Full URL mode leaves encoded structure characters such as %2F and %26 as they are. Invalid sequences trigger an error message.
Step 4: Copy and Use
Click Copy to use the result in URLs, API calls, configuration files, or debugging, or Swap to move the output back into the input. The tool handles both single-byte ASCII and multi-byte UTF-8 characters correctly.
Privacy
All encoding and decoding runs locally in your browser. No text is transmitted to any server.
Summary
URL encoding converts unsafe characters into percent-encoded sequences (%XX) so they can be safely included in URLs. The rules are defined by RFC 3986: 66 characters are unreserved (never encoded), 18 are reserved (encoded when used as data), and everything else — spaces, non-ASCII characters, control characters — must always be encoded.
The most common encoding: space → %20, ampersand → %26, equals → %3D, question mark → %3F. In JavaScript, use encodeURIComponent() for individual values and encodeURI() for complete URLs — never mix them up.
Encode and decode URLs with WritePadPro's URL Encoder & Decoder — instant percent-encoding with full UTF-8 support, running entirely in your browser.