Encoding · Developer Guide
URL Encoding Explained
Encoding the wrong part of a URL can change its structure. Decide whether you are encoding one value, building a query string, or inspecting a complete URL before selecting a tool.
What is percent encoding?
Percent encoding represents bytes as % followed by two hexadecimal digits. It lets a component contain characters that would otherwise serve as URL separators. The Small Tools encoder uses encodeURIComponent for one component, not a full URL.
How to build a query safely
Encode the value before joining it to a parameter name. For multiple parameters in application code, URLSearchParams handles query construction and form-style space encoding. Inspect the resulting query to confirm repeated keys and empty values have the meaning your server expects.
Example: keep an ampersand inside one value
Without %26, the ampersand could start another query parameter. Encoding the entire final URL would also encode its colon, slashes, and question mark, so it would no longer be usable as that URL.
Original value: Tom & Jerry
Encoded value: Tom%20%26%20Jerry
Final URL: https://example.com/search?q=Tom%20%26%20JerryCommon mistakes
- Double encoding: %20 becomes %2520 when passed through the encoder again. Track which layer owns encoding.
- Treating + the same everywhere: decodeURIComponent keeps + as +; form-style query parsing with URLSearchParams treats it as a space. A literal plus in a query value should be encoded as %2B.
- Decoding malformed percent sequences: incomplete escapes or invalid UTF-8 produce an error.
- Using percent encoding as HTML escaping: URL construction and safe HTML rendering solve different problems.
Practical use cases and limits
When a search term containing spaces, Unicode, or & fails, inspect the outgoing URL and compare the parsed query on the receiving side. For a signed URL, follow the signature protocol exactly; decoding and re-encoding can change bytes or parameter ordering and invalidate the signature.
The tools run locally and do not navigate to the supplied URL. Percent encoding does not hide tokens from browser history, server logs, or recipients of a shared link. Keep credentials out of URLs where possible.
Run it yourself
A Node.js v26.12.1 run printed the values in the block below. Small Tools URL Encoder returns Tom%20%26%20Jerry%2F%23%3F%2B%C3%A9 for the first input. URL Decoder turns a%2520b into a%20b (one layer per run), leaves a+b as a+b, and reports URI malformed for %E0%A4%A.
Three behaviors stand out. encodeURIComponent escapes separators such as / # ? and +, while encodeURI leaves them alone. Two layers of encoding turn a space into %2520. And a plus sign becomes a space only in form-style parsing such as URLSearchParams, not in decodeURIComponent.
encodeURIComponent("Tom & Jerry/#?+é")
// Tom%20%26%20Jerry%2F%23%3F%2B%C3%A9
encodeURIComponent(encodeURIComponent("a b"))
// a%2520b
decodeURIComponent("a+b")
// a+b
new URLSearchParams("q=a+b").get("q")
// "a b"
new URLSearchParams({ q: "Tom & Jerry" }).toString()
// q=Tom+%26+Jerry
encodeURI("https://example.com/a b?q=é&r=1")
// https://example.com/a%20b?q=%C3%A9&r=1
encodeURIComponent("https://example.com/a?b=1")
// https%3A%2F%2Fexample.com%2Fa%3Fb%3D1
decodeURIComponent("%E0%A4%A")
// URIError: URI malformedWhat this guide does not verify
- How a particular server, framework or proxy decodes the + character. Compare with the receiving system's documentation.
- Whether a proxy or CDN rewrites or normalizes percent encoding before your application sees the URL.
- Internationalized domain names. They use Punycode rather than percent encoding and are not covered here.
- Signed URLs and other protocols that define their own canonical encoding.
- Browsers other than Node.js. The examples were run in Node.js only; the Small Tools pages call the same JavaScript functions in your browser.
Frequently asked questions
Should I encode a whole URL? No. Encoding https://example.com/a?b=1 as one component gives https%3A%2F%2Fexample.com%2Fa%3Fb%3D1, which is no longer a usable URL. Encode each value, then assemble the URL.
Why does decoding a+b keep the plus sign? decodeURIComponent only decodes percent sequences. A plus sign means a space in form-style query strings, so URLSearchParams returns a b for q=a+b. If a plus must stay a plus, write it as %2B.
Is percent encoding the same as hiding data? No. Anyone can decode it, and the original value still appears in browser history, server logs and shared links.
Related tools
- URL Encoder — Encode text for safe use in URL components.
- URL Decoder — Decode percent-encoded URL components.
- Query String Parser — Decode a query string and group repeated parameter values.
- URL Parser — Break an absolute URL into its protocol, host, path, and query fields.