DevX Tool
Back to Tech Blog
Web Development 3 min read DevX Tool Team

URL Encoding: Spaces, Plus Signs, and Query Parameters

Understand %20, +, %2B, and double encoding. Build query parameters correctly with URLSearchParams and fix broken links with concrete examples.

URLs JavaScript APIs

What do %20, +, and %2B mean?

Percent encoding represents bytes as a percent sign followed by two hexadecimal digits. The rules depend on which part of a URL you are working with. In form-style query strings, + represents a space. In a URL path, it does not automatically have that meaning.

A plus sign in an email alias or a programming language name must survive decoding as a literal plus sign. For instance, a search for C++ should not become C followed by two spaces.

What do %20, +, and %2B mean?
Original valueencodeURIComponentURLSearchParams value
hello worldhello%20worldhello+world
C++C%2B%2BC%2B%2B
a&ba%26ba%26b
50%50%2550%25

Build a query string from raw values

Give URLSearchParams the unencoded values. It handles reserved characters during serialization. Use a URL object to keep the hostname, path, query, and fragment separate.

In this example, the plus sign in the address and the ampersand in the search phrase remain part of their values. Manually concatenating those values into a URL would make the ampersand look like the start of another parameter.

JavaScript
const url = new URL("https://example.com/search");
url.searchParams.set("q", "coffee & tea");
url.searchParams.set("email", "alex+news@example.com");
console.log(url.href);
// https://example.com/search?q=coffee+%26+tea&email=alex%2Bnews%40example.com
console.log(url.searchParams.get("email"));
// alex+news@example.com

Decode a component or parse a complete query

decodeURIComponent reverses percent encoding, but does not turn a plus sign into a space. That makes it suitable for an encoded component when you know the producer used percent encoding. Use URLSearchParams for a form-style query.

The DevX Tool URL decoder follows decodeURIComponent semantics. If you paste hello+world into it, the plus sign stays visible. This behavior is useful when a literal plus is intended, but it is not a substitute for parsing an entire form query.

JavaScript
console.log(decodeURIComponent("hello%20world")); // hello world
console.log(decodeURIComponent("hello+world"));   // hello+world
const params = new URLSearchParams("q=hello+world&lang=C%2B%2B");
console.log(params.get("q"));    // hello world
console.log(params.get("lang")); // C++

Fix %2520 and other double-encoding problems

The value %2520 usually means an existing %20 was encoded again: % becomes %25. This happens when you call encodeURIComponent and then pass the result to URLSearchParams, which performs another encoding pass.

Fix the producer so it passes raw values to the serializer exactly once. Do not repeatedly decode every received value until it stops changing. A literal value such as the text %20 may be intentional, and repeated decoding can alter paths or security checks.

JavaScript
const wrong = new URLSearchParams({ q: encodeURIComponent("New York") });
console.log(wrong.toString()); // q=New%2520York

const correct = new URLSearchParams({ q: "New York" });
console.log(correct.toString()); // q=New+York

International text and malformed escapes

Characters such as é are encoded as UTF-8 bytes, so one visible character can become multiple percent sequences. That is normal and works across countries; a URL does not need to be limited to English words.

An incomplete escape such as %2 or invalid UTF-8 can make decodeURIComponent throw URIError. Catch that error and report malformed input rather than silently changing the string. When debugging a request, compare the raw query in the network panel with the parsed value on the server.

Frequently asked questions

Should I encode an entire URL with encodeURIComponent?

Only when the complete URL is itself a value, such as a redirect query parameter. Encoding the whole destination URL directly also encodes its colon and slashes, so it is no longer a normal navigable URL.

Why did a Base64 plus sign turn into a space?

A form-style query parser interprets raw + as a space. Pass the original Base64 value to URLSearchParams.set so the plus sign is serialized as %2B.

References

Check the official documentation for command options and runtime-specific behavior.

Advertisement
Put Knowledge Into Practice

Integrated Tools & Learning Resources

DevX Tool combines deep engineering tutorials with client-side interactive tooling so you can test code, verify outputs, and troubleshoot bugs right away.

Related tutorials and articles