URL Encode & Decode · Tutorial
How to encode a value for a URL query parameter
5 min readbeginnerUpdated
You're building a link by hand, such as a pre-filled form, a search URL or a tracking link, and the value contains spaces, accents, & or #. Pasted as it is, part of the value disappears or the link breaks. This tutorial shows how to encode each value correctly and assemble a working URL.
What you need
- The URL Encode & Decode
- The values you want to put in the link (the Try it button loads a sample)
Steps
Identify the values
A query string is a list of
name=valuepairs joined by&, after a?. Only the values (and sometimes the names) need encoding, never the?,=and&that separate them. In the sample, the values areAmara Okafor,São PauloandOrder #42 & gift wrap.Encode each value
Choose A value (query parameter, path segment) and paste a single value, for example
Order #42 & gift wrap. The result isOrder%20%2342%20%26%20gift%20wrap. The#and&are now safe.Order #42 & gift wrap → Order%20%2342%20%26%20gift%20wrapEncode a list at once
To encode several values, put each on its own line and tick Each line separately. Each line is encoded on its own, so you can copy them one by one.
Assemble the URL
Join the encoded values with their names. Notice that
São PaulobecameS%C3%A3o%20Paulo, becauseãis two bytes in UTF-8.https://example.com/form?name=Amara%20Okafor&city=S%C3%A3o%20Paulo¬e=Order%20%2342%20%26%20gift%20wrapTest the link
Open the link in a browser and check that the page receives every value in full. You can also paste it into the URL Parser to see each parameter decoded.
Try it yourself
Opens the URL Encode & Decode with this tutorial's sample loaded.
Common mistakes
- Encoding the whole URL as a value
- If you encode the full link in value mode, its
:and/become%3Aand%2Fand the link stops working. Encode values only, or use A full URL for complete addresses. - Encoding twice
- Encoding an already-encoded value turns
%20into%2520. If you see%25, the text was encoded twice. - Using + for spaces in paths
- A
+means a space only in form-encoded query strings. In a URL path it's a literal plus sign. Use%20unless you're sure the receiver expects form encoding.
Next steps
Go back to the URL Encode & Decode, or keep going with one of these:
FAQ
Do I need to encode letters with accents?
Modern browsers display them fine, but many systems, emails and older software don't handle raw non-ASCII URLs well. Encoding is always safe.