Encode/decode URL-formatted strings

Percent-encode text or decode it back.

loading Encode/decode URL-formatted strings
About this tool

What is URL encoding?

URL encoding, also called percent-encoding, is how text that is not allowed in a web address gets carried inside one. Each unsafe character is replaced by a % followed by its byte value in hexadecimal: a space becomes %20, & becomes %26, and a non-ASCII letter such as é becomes its two UTF-8 bytes, %C3%A9. The rules come from RFC 3986. Without encoding, a value like rock & roll in a query string would be read as the end of one parameter and the start of another, and the server would receive the wrong data.

You need it whenever you build a link by hand: a search term in ?q=, a redirect URL passed inside another URL, a file name in a Content-Disposition header, a value in an API call or a tracking parameter. Decoding is the opposite job: turning caf%C3%A9%20com%20leite back into readable text when you inspect logs, analytics reports or a webhook payload. For text placed inside HTML rather than a URL, the equivalent job is done by HTML entities.

The catch is that there is no single "right" encoding. JavaScript's encodeURIComponent leaves ! ' ( ) * alone, strict RFC 3986 encodes them, encodeURI keeps the structure of a whole address, and HTML forms send spaces as +. This URL encoder and decoder lets you pick the exact rule your system expects, shows a hint for each one, and explains decoding errors with the position of the problem. It all runs in your browser, so you can paste URLs that contain tokens or personal data without sending them anywhere.

How to encode or decode a URL online

  1. In the Encode card, choose the rule in Encoding: Component (encodeURIComponent) for a single query value or path segment, Strict RFC 3986 when the other side is strict (OAuth signatures, AWS), Whole URI (encodeURI) to fix a full address without breaking its / ? & =, or RFC 5987 (Content-Disposition) for the filename*= of a download header.
  2. Type or paste the text in Your string. The encoded result appears below as you type; press Copy encoded.
  3. To decode, paste the encoded text in the Decode card, under Your encoded string.
  4. If the text comes from an HTML form or a query string where spaces were written as +, turn on Read + as a space (form data).
  5. Press Copy decoded. Your encoding choice and the + switch are remembered for the next visit. There is also a page that opens straight on URL decoding.

Examples

The same text in the four modes

Input Hello world :):

ModeOutput
ComponentHello%20world%20%3A)
Strict RFC 3986Hello%20world%20%3A%29
Whole URIHello%20world%20:)
RFC 5987Hello%20world%20%3A%29

Fixing a full address with accents and spaces

Mode Whole URI:

https://example.com/search?q=crème brûlée&page=2

Output:

https://example.com/search?q=cr%C3%A8me%20br%C3%BBl%C3%A9e&page=2

The :, /, ?, & and = stay as they are, so the URL still works. With Component the same input would become https%3A%2F%2Fexample.com…, which is only right when the whole URL is a value inside another URL, such as a redirect_uri.

A file name for a download header

Mode RFC 5987, input Q3 report (final)'s.pdf:

Q3%20report%20%28final%29%27s.pdf

Use it as Content-Disposition: attachment; filename*=UTF-8''Q3%20report%20%28final%29%27s.pdf.

Decoding form data

Input q=hello+world%21 with Read + as a space on gives q=hello world!. With the switch off, the + stays: q=hello+world!.

Text encoded twice

Decoding caf%25C3%25A9 gives caf%C3%A9, which still looks encoded: %25 is an encoded %. Decode the result once more to get café, then fix the code that encodes twice.

Common errors and how to fix them

  • "Invalid percent sequence at position 4: "%" must be followed by two hex digits": the text has a literal %, as in 100%. Every % must start a sequence like %20; write a real percent sign as %25.
  • "These bytes are not valid UTF-8 (for example a lone %E0)": the sequence is cut, or the text was encoded in Latin-1 (%E9 for é instead of %C3%A9). Get the original again, or re-encode it as UTF-8.
  • "This text has a lone surrogate character (half of an emoji)": a copy-paste broke an emoji in half. Delete it and paste the whole emoji; 👍 ok encodes fine as %F0%9F%91%8D%20ok.
  • The server receives + instead of spaces: the server decodes with decodeURIComponent, which does not treat + as a space. Send %20, or make the server decode as form data.
  • Links break after encoding: you encoded a whole URL with Component. Use Whole URI, or encode only the values.

Frequently asked questions

What is the difference between encodeURI and encodeURIComponent?

encodeURI is for a complete address: it keeps ; , / ? : @ & = + $ #, so the structure survives. encodeURIComponent is for one piece, such as a query value, and encodes those characters too. Using the wrong one is the most common URL bug.

Should a space be %20 or +?

Both mean a space, in different places. %20 is valid everywhere in a URL; + means a space only in query strings sent as application/x-www-form-urlencoded (HTML forms). When in doubt, send %20.

Why does é become %C3%A9?

URLs carry bytes, and é takes two bytes in UTF-8: C3 and A9. Each byte gets its own % sequence.

Is URL encoding a form of encryption?

No. Anyone can decode it, so it hides nothing. To transport binary data use Base64; to protect it you need encryption.

How do I see each part of a URL separately?

Paste it into the URL parser: it splits protocol, host, path and every query parameter, already decoded.

How to encode a URL in code

JavaScript

encodeURIComponent for values; URLSearchParams builds a whole query string the way forms do (spaces as +).

console.log(encodeURIComponent('café & pão'));             // caf%C3%A9%20%26%20p%C3%A3o
console.log(decodeURIComponent('caf%C3%A9%20%26%20p%C3%A3o'));
console.log(new URLSearchParams({ q: 'café & pão', page: '2' }).toString());
// q=caf%C3%A9+%26+p%C3%A3o&page=2

Python

quote(..., safe="") matches the strict RFC 3986 mode; urlencode builds form-style query strings.

from urllib.parse import quote, unquote, unquote_plus, urlencode

print(quote("café & pão", safe=""))               # caf%C3%A9%20%26%20p%C3%A3o
print(unquote("caf%C3%A9%20%26%20p%C3%A3o"))      # café & pão
print(urlencode({"q": "café & pão", "page": 2}))  # q=caf%C3%A9+%26+p%C3%A3o&page=2
print(unquote_plus("q=hello+world%21"))           # q=hello world!

Go

url.PathEscape for path segments, url.QueryEscape for query values (spaces as +).

package main

import (
	"fmt"
	"net/url"
)

func main() {
	fmt.Println(url.PathEscape("café & pão"))  // caf%C3%A9%20&%20p%C3%A3o
	fmt.Println(url.QueryEscape("café & pão")) // caf%C3%A9+%26+p%C3%A3o
	s, err := url.QueryUnescape("q%3Dhello+world%21")
	if err != nil {
		panic(err)
	}
	fmt.Println(s) // q=hello world!
}

Bash

jq encodes with the strict rule; curl --data-urlencode encodes query values for you.

printf '%s' 'café & pão' | jq -sRr @uri          # caf%C3%A9%20%26%20p%C3%A3o
curl --get --data-urlencode 'q=café & pão' https://example.com/search
Report a problem