Plus Sign vs Space in URL Query Parameters

Learn why plus signs become spaces in form-encoded query parameters, how to preserve literal plus signs, and how to check encoding round trips.

Published
Reading time
6 min read
Plus Sign vs Space in URL Query Parameters
On this page

A plus sign in a query parameter can mean either a literal + or a space, depending on how the receiver interprets the query. This distinction causes problems when an HTML form or API sends values such as C++, email addresses, or search terms. This guide shows how to encode and decode those values without losing information.

Key Takeaways

  • In application/x-www-form-urlencoded data, + represents a space and %2B represents a literal plus sign.
  • %20 also decodes to a space in form-encoded data. %26 preserves an ampersand inside a value rather than treating it as a parameter separator.
  • JavaScript’s URLSearchParams applies form-style encoding and decoding. encodeURIComponent() and decodeURIComponent() do not convert between spaces and plus signs.
  • Encode individual names and values, not an already assembled query string. Parse the query before decoding its components.

Why plus signs turn into spaces

HTML forms commonly submit query parameters using the application/x-www-form-urlencoded convention. Under this convention, a parser interprets a raw + in a name or value as a space. To transmit an actual plus sign, encode it as %2B.

For example, a form-style parser reads these query strings as follows:

Query stringDecoded q value
q=C++C — C followed by two spaces
q=C%2B%2BC++
q=hello+worldhello world
q=hello%20worldhello world
q=fish%26chipsfish&chips

The characters & and = also matter: in a form-encoded query, & separates parameters and = separates a name from its value. An unencoded ampersand in a value can therefore create an unintended parameter.

Advertisement

Form encoding versus general URL percent-encoding

Percent-encoding represents a byte using % followed by two hexadecimal digits. A space can be represented as %20, a plus sign as %2B, and an ampersand as %26.

The special interpretation of + as a space comes from the form-encoding convention; it is not a universal rule for every URL component or every query parser. A receiver that does not use form-style decoding may treat a raw plus as a literal plus. Check the API’s contract rather than assuming both sides use the same convention.

For the value C++ guide&tips, these are two useful encodings:

Encoding approachEncoded valueExample query
Form-style serializationC%2B%2B+guide%26tipsq=C%2B%2B+guide%26tips
JavaScript encodeURIComponent()C%2B%2B%20guide%26tipsq=C%2B%2B%20guide%26tips

A form-style decoder recovers the same value from either example because it accepts both + and %20 for a space. A different API may impose a more specific encoding contract.

encodeURIComponent() encodes a single component; it is not a complete query-string builder or a strict encoder for every character reserved by RFC 3986. For example, it leaves !, ', (, ), and * unescaped. Follow the receiving API’s rules if it requires stricter encoding, especially for request signing.

Build and read form-style queries in JavaScript

For a browser or a Node.js environment with the standard URLSearchParams API, pass the original value to the API rather than pre-encoding it:

const value = 'C++ guide&tips';
const params = new URLSearchParams();
params.set('q', value);

const query = params.toString();
console.log(query); // q=C%2B%2B+guide%26tips

const decoded = new URLSearchParams(query).get('q');
console.log(decoded); // C++ guide&tips

URLSearchParams encodes parameter names as well as values. When reading a full URL, use new URL(url).searchParams; pass only a query string to new URLSearchParams(query) rather than an entire URL.

Do not pre-encode the value before calling set(). For example, passing C%2B%2B causes the percent signs to be encoded again, producing C%252B%252B. After one normal decoding pass, the receiver gets C%2B%2B, not C++.

Decoding a standalone form-encoded value

If you must decode one isolated form-encoded component without a query parser, replace raw plus signs before percent-decoding:

function decodeFormComponent(encoded) {
  return decodeURIComponent(encoded.replace(/\+/g, ' '));
}

console.log(decodeFormComponent('C%2B%2B+guide%26tips'));
// C++ guide&tips

The order matters: replacing + after percent-decoding would incorrectly turn a decoded %2B into a space. decodeURIComponent() can throw a URIError for malformed escapes or invalid encoded UTF-8, so handle that error at your application boundary. For a complete query string, use a query parser instead of this helper.

Advertisement

Round-trip checks

Save the following as query-roundtrip.mjs and run it with a modern Node.js installation using node query-roundtrip.mjs. It uses Node’s built-in assertion module and does not need an external package.

import assert from 'node:assert/strict';

const cases = [
  ['literal plus', 'C++', 'q=C%2B%2B'],
  ['space', 'hello world', 'q=hello+world'],
  ['ampersand', 'fish&chips', 'q=fish%26chips'],
  ['combined', 'C++ guide&tips', 'q=C%2B%2B+guide%26tips'],
];

for (const [label, value, expectedQuery] of cases) {
  const params = new URLSearchParams();
  params.set('q', value);
  const query = params.toString();

  assert.equal(query, expectedQuery, `${label}: serialization`);
  assert.equal(new URLSearchParams(query).get('q'), value, `${label}: round trip`);
}

assert.equal(new URLSearchParams('q=C++').get('q'), 'C  ');
assert.equal(new URLSearchParams('q=hello%20world').get('q'), 'hello world');
assert.equal(decodeURIComponent('hello+world'), 'hello+world');

console.log('All query encoding checks passed.');

The expected output is All query encoding checks passed. The examples have not been executed in this environment. The URL Standard and platform documentation could not be retrieved here, so consult the documentation for your target runtime and API before relying on version-specific behavior.

Troubleshoot an integration

  1. Capture the serialized request safely. Inspect the raw query sent on the wire and the value received by the server. Redact credentials, personal data, and other secrets before logging or sharing it.
  2. Check the receiver’s contract. Determine whether it uses form-style query decoding. A generic URL parser, a framework’s query parser, and an API-specific signature verifier may apply different rules.
  3. Look for the first transformation. If C++ arrives as C , check whether raw plus signs were sent. If C%2B%2B arrives literally, look for double encoding or an extra decoding step.
  4. Check delimiters and duplicates. A raw & can split a value into another parameter. If a name appears more than once, use the framework’s documented duplicate-parameter behavior; in JavaScript, getAll() retrieves all values.
  5. Add regression cases. Include plus signs, spaces, ampersands, percent signs, empty values, non-ASCII text, and duplicate names where your contract permits them.

Common Mistakes

  • Assuming decodeURIComponent() is a form parser. It decodes %20 but leaves a raw + unchanged.
  • Decoding the whole query before splitting it. Turning %26 into & first can make data look like a separator. Let a query parser identify parameters and decode their components.
  • Encoding the complete query with encodeURIComponent(). This also encodes structural separators such as & and =, so the receiver may see one component instead of several parameters.
  • Manually concatenating untrusted values. Raw &, =, +, #, or % can change how a URL or its query is interpreted.
  • Treating query encoding as validation. Correct encoding preserves data; it does not establish that the value is valid or safe for a downstream operation.

Best Practices

Use a query builder and parser that match the receiving endpoint’s contract. Pass raw values to the builder once, and decode once at the receiving boundary. For signatures or canonical request formats, follow the provider’s exact rules for escaping, ordering, and duplicate parameters rather than substituting form serialization.

Conclusion

For form-encoded queries, send literal plus signs as %2B and spaces as + or %20. Use a matching parser on the receiving side, and keep round-trip checks for the characters your integration must preserve.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.