Skip to content

URL Encoding: Which Characters Need Escaping and Why

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:

CategoryCharacters
Uppercase lettersA 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 lettersa 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
Digits0 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):

CharacterEncodedURL Meaning
:%3ASeparates scheme from authority (https://)
/%2FPath separator (/blog/post)
?%3FStarts query string (/search?q=term)
#%23Fragment identifier (page#section)
&%26Query parameter separator (a=1&b=2)
=%3DKey-value separator (key=value)
+%2BSpace in some form encodings
@%40User info separator (user@host)
!%21Sub-delimiter
$%24Sub-delimiter
'%27Sub-delimiter
(%28Sub-delimiter
)%29Sub-delimiter
*%2ASub-delimiter
,%2CSub-delimiter
;%3BParameter 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:

CharacterEncodedNotes
Space%20 (or +)Most common encoding; + is allowed in query strings only
<%3CHTML tag opener — security risk if unencoded
>%3EHTML tag closer
"%22Attribute delimiter
{%7BNot allowed in URLs
}%7DNot allowed in URLs
|%7CNot allowed in URLs
\%5CNot allowed in URLs
^%5ENot allowed in URLs
`%60Not 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

ScenarioCorrect FunctionWhy
Encoding a full URLencodeURI()Preserves :// / ? = & structure
Encoding a query parameter valueencodeURIComponent()Encodes & = so they become data, not structure
Encoding a path segmentencodeURIComponent()Encodes / so it becomes data, not a path separator
Encoding form dataencodeURIComponent()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.

Frequently Asked Questions

What is the difference between %20 and + for spaces?

Both represent a space character in URLs, but in different contexts. %20 is the standard percent-encoding for space defined by RFC 3986 and works everywhere in a URL — path, query string, fragment. The + sign represents a space only in the application/x-www-form-urlencoded format used by HTML form submissions with GET method. In path segments, + is a literal plus sign, not a space. The safest approach is to always use %20 for spaces. JavaScript's encodeURIComponent() produces %20 (correct). Older form encoding produces + (context-specific).

What is the difference between encodeURI and encodeURIComponent?

encodeURI() encodes a complete URL — it preserves structural characters like :, /, ?, #, and & because they have meaning in the URL structure. encodeURIComponent() encodes a single value within a URL — it encodes :, /, ?, &, and other delimiters because within a value, these characters are data, not structure. Use encodeURI() when you have a full URL and want to fix spaces and non-ASCII characters. Use encodeURIComponent() when you have a query parameter value, path segment, or any piece of data being inserted into a URL. WritePadPro's URL Encoder & Decoder offers both, as Full URL and Component modes.

Do I need to URL-encode emoji in URLs?

Yes. Emoji and all non-ASCII characters must be percent-encoded for transmission over HTTP. The emoji fire symbol (U+1F525) becomes %F0%9F%94%A5 — four percent-encoded bytes because the emoji is 4 bytes in UTF-8. Modern browsers display the emoji in the address bar for readability (as an IRI — Internationalized Resource Identifier) but transmit the percent-encoded form over the network. Always encode non-ASCII characters in URLs to ensure compatibility across all browsers, servers, and intermediary systems.

Why do URLs break when they contain spaces?

The URL specification (RFC 3986) does not allow space characters in URLs. A space signals the end of a URL in many contexts — HTTP headers, HTML attributes, command line arguments, and plain text. When a browser encounters a space in a URL, it either truncates the URL at the space or replaces the space with %20 automatically. Server software may reject the URL entirely. Always encode spaces as %20 in URLs to ensure they are transmitted correctly. WritePadPro's URL Encoder handles this conversion instantly.

How are non-English characters encoded in URLs?

Non-ASCII characters (accented letters, CJK characters, Arabic, Cyrillic, etc.) are first converted to their UTF-8 byte sequences, then each byte is individually percent-encoded. The German umlaut ü (U+00FC) becomes %C3%BC (two bytes). The Chinese character 中 (U+4E2D) becomes %E4%B8%AD (three bytes). Modern browsers display these as readable characters in the address bar (IRI format) but transmit the percent-encoded version over HTTP. This ensures URLs work correctly regardless of the user's operating system language or character encoding settings.

Try These Tools

Related Articles