URL guide

Why plus means space in form-encoded URLs

In application/x-www-form-urlencoded data, a plus sign can decode as a space. Encode a literal plus as %2B.

Open URL Encode Decode Tool View all tools

Why + turns into a space

The plus sign has a special rule in application/x-www-form-urlencoded data. In that format, spaces may be serialized as plus signs, so a form decoder may turn + back into a space. Search forms rely on that shortcut, but literal plus values break: C++, phone numbers, math expressions, Base64 text, and timezone offsets. Outside form-style query handling, %20 is the encoded space and %2B is the literal plus sign.

Example

Input

q=C++ guide&phone=+12025550123

Output

q=C%2B%2B+guide&phone=%2B12025550123

How to encode literal plus signs

  1. Check the receiving format first. If the server uses application/x-www-form-urlencoded parsing, raw plus signs may become spaces.
  2. Encode a literal plus as %2B before putting it into a query value or form body.
  3. Use %20 when you need an encoded space outside form-style serialization, especially in paths and nested callback URLs.
  4. When using URLSearchParams, pass raw values and let the serializer encode them. Do not pre-encode a value and then encode it again.
  5. After building the URL, parse it back and compare the exact value received by the application.

Query strings and form bodies

A query string can be parsed by many different libraries. Some treat plus as a space because they follow form-style rules. Others keep plus literal unless the caller applies form decoding.

That difference is why bugs often appear only after a URL reaches a backend framework. The browser may display a plus sign, but the server-side parser may hand your handler a space.

Nested URLs and callbacks

If you put a URL inside another URL, encode the nested value as one parameter. A plus sign inside the nested URL may be literal, while spaces in the outer form encoding may serialize as plus signs.

For OAuth redirects, webhook callbacks, and search links, test the final parsed parameter rather than relying on how the address bar looks.

Common mistakes

  • Sending q=C++ and receiving two spaces after C because both plus signs became spaces
  • Using plus signs for spaces in URL paths
  • Encoding + as %2B and then encoding again into %252B
  • Mixing a query parser, form body parser, and manual string concatenation
  • Assuming percent decoding and form decoding follow the same plus-sign rule everywhere

Related problems

FAQ

Does plus always mean space in a URL?

No. The plus-as-space rule belongs to form-style encoded data. In other URL parts, a literal plus can remain a plus.

How do I encode a literal plus sign?

Encode a literal plus as %2B when the value may go through form decoding.

Are spaces + or %20?

Use %20 as the general encoded space. Use + only when producing application/x-www-form-urlencoded values.