URLs
Encode a URL value without breaking the link
Build query strings that preserve ampersands, plus signs, spaces, and nested URLs, and learn when URLSearchParams is the better choice.
Open URL Encoder/DecoderSeparate URL syntax from your data
Imagine a search link for tea & cake. If you write ?q=tea & cake directly, the ampersand can be interpreted as the start of another parameter. It belongs to the phrase, so encode the value as tea%20%26%20cake before placing it after q=.
Zentoolia’s URL Encoder/Decoder uses encodeURIComponent and decodeURIComponent. These operate on one value rather than preserving the structure of a complete URL. Use the tool to inspect the encoded component, and leave the question mark, parameter names, equals signs, and separating ampersands in the surrounding URL structure.
Raw value: tea & cake
Encoded value: tea%20%26%20cake
Full URL: https://example.com/search?q=tea%20%26%20cakeSometimes the whole URL is the value
A redirect or share parameter can contain another URL. In that situation, escaping the inner URL’s colon, slashes, and separators is intentional. The outer link still needs its own unescaped structure. The encoded value should decode back to the exact inner URL.
For example, an inner URL containing ?page=2&sort=date must remain one value in the outer query. Without encoding, its ampersand could create a sort parameter on the outer link instead. In application code, use the URL and URLSearchParams APIs to do this assembly rather than manually joining arbitrary input.
const link = new URL("https://example.com/share");
link.searchParams.set("target", "https://example.com/list?page=2&sort=date");
console.log(link.href);A plus sign depends on the decoding convention
decodeURIComponent leaves a literal + unchanged. It converts %20 to a space and %2B to a plus. By contrast, form-style query parsing treats a literal + as a space. This distinction explains why a value can look correct in a component decoder and different when a form library reads it.
To preserve C++ as a form query value, let URLSearchParams encode it so the plus signs become %2B. When inspecting form data, parse it using the form convention. Do not indiscriminately replace all plus signs in an arbitrary URL or a Base64 value.
decodeURIComponent("C++"); // "C++"
decodeURIComponent("C%2B%2B"); // "C++"
new URLSearchParams("q=C++").get("q"); // "C "
new URLSearchParams({q: "C++"}).toString(); // "q=C%2B%2B"Encode once at the correct boundary
Encoding the already encoded text tea%20cake produces tea%2520cake, because % itself becomes %25. One decoding pass then produces tea%20cake, not tea cake. This is a common symptom of encoding in both a UI component and a network helper.
Keep raw application values until the boundary where the URL is assembled. If you use URLSearchParams, pass the raw value and let it perform the encoding. Only decode the layers your protocol defines; repeatedly decoding until a value stops changing can reinterpret data as syntax and undermine validation.