Guide

Spaces in URLs: %20 vs +

Learn when a space becomes %20 or +, how to preserve a literal plus sign, and which encoding belongs to each context.

by Tools in a Tab · Published on · Reviewed on

Short answer

%20 represents a space through percent-encoding in a URL. A plus sign represents a space specifically in application/x-www-form-urlencoded data, which is often used for queries and forms. Outside that format, + can be a literal plus sign. To preserve it in form data, encode it as %2B.

Three inputs with different meanings

Suppose you need to transport these values:

Original value Percent-encoded component URL-encoded form
black coffee black%20coffee black+coffee
a+b a%2Bb a%2Bb
a b a%20b a+b

The ambiguity appears when a+b is decoded under form rules: the output is a b, not the original plus sign. A + that belongs to the data must therefore arrive as %2B in that context.

Which rule each API uses

encodeURIComponent("a b") returns a%20b. By contrast, URLSearchParams serializes the space as + because it uses form encoding. Both outputs can be correct; they implement different algorithms for different contexts.

The percent-encoding section of RFC 3986 defines the %HH form. The WHATWG URL Standard defines the application/x-www-form-urlencoded algorithm that turns a space into +.

What the tool does

Tools in a Tab’s URL encoder and decoder works with components through operations equivalent to encodeURIComponent and decodeURIComponent. A space is consequently encoded as %20; the decoder does not automatically treat + as a space.

That is appropriate for safely building a segment or component value. If you need to reproduce a form body exactly, use URLSearchParams or the query string parser, which applies form rules while keeping every name, value, and repeated occurrence separate.

Practical rule

  1. Identify whether you are encoding a URL component or form data.
  2. For components, expect %20 for a space.
  3. For URL-encoded form data, expect + for a space.
  4. Encode a literal plus as %2B whenever the receiver applies form rules.

Do not replace every + with a space without knowing the format. That shortcut can change valid data.