Percent-encoding for one query component
URL encode and decode
Reserved characters in a URL have jobs. A space, an ampersand, or an equals sign inside a value must be escaped or the query will split in the wrong place.
Component mode uses encodeURIComponent. Space becomes %20, and & = ? # / all become percent sequences. Form mode is the application/x-www-form-urlencoded habit: after that encoding, %20 is written as +. Decoding reverses the same choice. This page encodes one value. It does not build a whole ?a=1&b=2 string. That job is on the query string page.
The string is encoded in this tab and is not sent to Glazlo.
This tool runs in your browser. Turn on JavaScript to use it.
A value that would break a query
The spaces and the ampersand are data, not separators. Component encoding keeps them inside one field.
- Value
- a b&c=d
- Component
- a%20b%26c%3Dd
- Form body
- a+b%26c%3Dd
How to use it
- 1Paste the raw value, not a full URL, unless you really want the colon and slashes encoded too.
- 2Pick component encoding for a query value. Pick form encoding for a body that uses + for spaces.
- 3Decode with the same mode you encoded with, or a plus sign will remain a plus.
Good to know
- encodeURI would leave / ? & = alone. This page does not use it, because those characters are unsafe inside a single value.
- A malformed % sequence, such as %ZZ, cannot be decoded.
- Build a full query on the query string page. Encode a single piece here.
Questions
Should a space be %20 or +?
In a query component, %20 is the safe choice. In an HTML form body, + is common. Decoding has to know which one was used.
Will this encode an entire URL?
It will, and the :// will be escaped too. Encode the value only if you are inserting it into a URL you already have.
Is this the same as Base64?
No. Percent-encoding marks bytes that are not allowed. Base64 repacks every byte into a 64-character alphabet.
Related tools
- Split a URL into parts
A URL is several fields joined by punctuation. This page uses the browser's URL parser and lists each part, including every query parameter.
- Parse and build a query string
A query string is a list of pairs, not one encoded blob. This page splits q=red&size=42 into rows you can edit, then joins them back.
- Convert a domain to Punycode
DNS labels are ASCII. Punycode stores the other characters in a label that starts with xn--. This page converts each label and leaves an already-ASCII label alone.