Skip to content

URL Encoder: Percent-Encode Special Characters

Percent-encodes text for use in URLs. Converts spaces, symbols, and Unicode characters into %XX sequences, the same rules JavaScript's encodeURIComponent uses.

URL String Escaper

Loading calculator...
📚

Documentation

URL Encoding: What It Is and How It Works

URL encoding, also called percent-encoding, is a way to represent characters in a web address using only a small set of safe ASCII characters. It works by replacing an unsafe character with a % sign followed by two hexadecimal digits. This URL string escaper tool encodes text the same way JavaScript's built-in encodeURIComponent function does.

Why URLs Need Encoding

A URL is only allowed to contain a limited set of characters: letters, digits, and a handful of punctuation marks. Spaces, accented letters, characters from non-Latin alphabets, and symbols such as & or = can break a URL or change its meaning if they appear in it unencoded. A space inside a link, for example, can cause a browser or server to read the URL as two separate pieces. Percent-encoding replaces these characters with a code that every browser and server can read the same way.

Characters This Tool Leaves Unchanged

This tool never touches the following characters. They pass straight through:

  • Uppercase and lowercase letters: AZ, az
  • Digits: 09
  • The punctuation marks - . _ ~ ! * ' ( )

Every other character gets percent-encoded, including:

  • The space character, and punctuation such as : / ? # [ ] @ $ & + , ; =
  • Accented letters and any other non-ASCII or Unicode character
  • A literal % character itself, which always becomes %25, even if it was already part of a percent-encoded sequence

Some general guides to URL syntax group ! * ' ( and ) together with other punctuation as characters that "may need encoding" in some contexts. This specific tool does not encode them, because it follows the encodeURIComponent rule set, where they are treated as safe.

How to Calculate a Percent-Encoded String (Formula)

The tool checks each character of the input one at a time and applies this rule:

  1. If the character is one of the unchanged characters listed above, keep it as is.
  2. Otherwise, convert the character to its UTF-8 byte sequence. Most Western European accented letters use two bytes; characters from scripts such as Chinese or Arabic often use three.
  3. Write each byte as a two-digit hexadecimal number.
  4. Put a % in front of each hexadecimal pair.
  5. Join the results together in order to form the encoded string.

Example

Input: Jürgen & Björk

Working through it character by character:

CharacterResult
JJ (unchanged)
ü%C3%BC (UTF-8 bytes 0xC3, 0xBC)
rgenrgen (unchanged)
(space)%20
&%26
(space)%20
BjBj (unchanged)
ö%C3%B6 (UTF-8 bytes 0xC3, 0xB6)
rkrk (unchanged)

Output: J%C3%BCrgen%20%26%20Bj%C3%B6rk

A second example shows the unchanged set at work. Encoding the string -_.!~*'() produces -_.!~*'(), exactly the same text, because every character in it belongs to the unreserved set. Encoding the string 100% produces 100%25, because the % sign itself is not a safe character.

Decoding a Percent-Encoded String

Decoding reverses the process: each %XX sequence is read as a hexadecimal byte, the bytes are grouped back into their original UTF-8 character, and the character replaces the sequence. For example, %C3%BC decodes back to ü, and %20 decodes back to a space. This tool only encodes; a separate decoder is needed to reverse the process.

Common Uses

Percent-encoding is used whenever text that a person typed, rather than text written by a programmer, needs to become part of a URL:

  • Search boxes that put the search term into the address bar, such as ?q=shoes%20%26%20bags
  • Query parameters carrying names, addresses, or other user data
  • Links to pages with titles in languages that use accented letters or non-Latin scripts
  • API requests that pass tokens or identifiers as part of the URL

Code Examples

1// JavaScript
2encodeURIComponent("Jürgen & Björk");
3// "J%C3%BCrgen%20%26%20Bj%C3%B6rk"
4

History

The idea of encoding unsafe characters in a URL goes back to RFC 1738 in 1994, one of the first documents to define the URL format. RFC 3986, published in 2005, updated the rules and formally defined the set of "unreserved" characters that never need encoding. encodeURIComponent, the JavaScript function this tool is built on, follows a slightly broader unreserved set than RFC 3986: it also leaves ! * ' ( and ) unencoded, matching an earlier version of the URI specification.

Frequently Asked Questions

What is the difference between URL encoding and URL escaping? They are the same thing. Both terms describe percent-encoding, where a character is replaced with % followed by two hex digits.

Why do !, *, ', (, and ) stay unchanged in this tool? This tool uses encodeURIComponent, which treats those five characters as safe and leaves them exactly as typed. Other encoding functions, and some servers, may still expect them to be encoded, so check the destination system if this causes a problem.

What is the difference between %20 and + for a space? Both represent a space. %20 is the general percent-encoding for a space. The + sign is a special case used only inside application/x-www-form-urlencoded data, the format used by HTML form submissions, not by this tool.

Does this tool decode already-encoded text? No. It only encodes. If the input already contains a % sign, that % is treated as a literal character and becomes %25 in the output, rather than being left alone.

How are non-Latin characters, such as Chinese or Arabic text, handled? Each character is first converted to its UTF-8 byte sequence, then every byte is percent-encoded. Most Chinese characters use three bytes, so one Chinese character produces three %XX groups in the output.

Should I encode an entire URL or just part of it? Only encode the parts that hold user data, such as query values or path segments, not the parts that form the URL's structure, such as https:// and the domain name. Encoding a full URL with a component encoder would also turn its :, /, and ? characters into percent codes, breaking the address.

References

  1. RFC 3986 — Uniform Resource Identifier (URI): Generic Syntax
  2. Percent-encoding — Wikipedia
  3. MDN — encodeURIComponent()
  4. URL Standard — WHATWG