URL Encode / Decode

Percent-encode query values or whole URLs, or decode them back to plain text.

Direction
0 characters

Or drop a .txt file onto the box above.

Encode as

How to use

  1. Choose Encode or Decode.
  2. For encoding, say what the text is under Encode as: a single value (one query parameter or path segment), a whole URL, or a form field.
  3. For decoding, leave Treat "+" as a space on for query strings and form data; turn it off for a path where + is a literal plus.
  4. Copy to clipboard, or ⇄ Swap to run the result back the other way.

Why URLs need percent-encoding

A URL can only safely contain a limited set of characters: letters, digits, and a handful of punctuation marks that have no special meaning in that position. Everything else (spaces, ampersands inside a value, non-English characters, slashes inside a value rather than as a path separator) has to be percent-encoded: replaced with % followed by its byte value in hex, as laid out in RFC 3986 §2.1. A space becomes %20, an ampersand becomes %26, and a character outside ASCII becomes one %XX group per UTF-8 byte.

Get this wrong and a URL either breaks outright or, worse, silently does the wrong thing. An unencoded &inside a query value looks like the start of the next parameter, quietly truncating or corrupting the one before it.

Example

Encoding hello world & more/less? as a single value gives:

hello%20world%20%26%20more%2Fless%3F

Every character outside letters, digits and -_.~ is escaped, including the slash and question mark, since as a value they carry no special meaning.

Component vs. full-URL encoding

The common mistake is running an entire URL through component-style encoding, which escapes the very characters (:, /, ?, &, =) that make it a URL in the first place. The rule of thumb: encode a value that will be placed inside a URL with the component option; only use the full-URL option on something that is already a complete, structurally valid URL and only needs its non-ASCII or space characters escaped. https://x.y/p q?a=b c&d=é#h in whole-URL mode becomes:

https://x.y/p%20q?a=b%20c&d=%C3%A9#h

Options explained

Edge cases and common errors

Do the same thing in code

JavaScript

encodeURIComponent("hello world & more");  // "hello%20world%20%26%20more"
encodeURI("https://x.y/p q?a=b c");        // "https://x.y/p%20q?a=b%20c"
decodeURIComponent("hello%20world");       // "hello world"
new URLSearchParams({ q: "a b+c" }).toString(); // "q=a+b%2Bc" (form encoding)

Python

from urllib.parse import quote, unquote, quote_plus
quote("hello world & more")   # 'hello%20world%20%26%20more'
quote_plus("hello world")     # 'hello+world'
unquote("hello%20world")      # 'hello world'

URL Encode / Decode FAQ

What is the difference between the three encode options?

A single value (encodeURIComponent) escapes everything that isn’t a letter, digit or a small set of safe symbols; use it for one query parameter's value. A whole URL (encodeURI) leaves characters like : / ? # & = alone since they are structural, not data, so use it when you have a complete URL you don’t want to break. Form field encoding is the same as a single value but turns spaces into "+", matching how HTML forms submit data.

Why would encoding the same text two different ways give different results for spaces?

A space becomes %20 under encodeURIComponent/encodeURI, but becomes + under the form-field convention (application/x-www-form-urlencoded), which is what browsers use for classic HTML form submissions.

When does decoding fail?

Percent-encoding is only valid when a "%" is followed by exactly two hexadecimal digits, and the bytes those digits spell out must form valid UTF-8. Text that was cut off mid-sequence, contains a literal "%" that was never encoded, or was encoded in Latin-1 by an old system fails to decode. The tool says which of the two it was rather than guessing.

Runs entirely in your browser: this page is a static file with no server behind it, so nothing you paste can be uploaded. Last reviewed by Parthesh Gupta. Implements RFC 3986 §2.1 (percent-encoding).