Developer tools

How do you put spaces, ampersands, and URLs inside a query parameter?

Encode one query-parameter value before building a share link or API request, then decode it to verify that special characters stayed inside the value.

4 min read 793 words

Encode the value before you attach it to the query string

An ampersand inside a value can look exactly like the ampersand that starts the next parameter. The safe habit is to encode each value first, then join the finished name=value pairs with &. Use the URL encoder (url-encoder) on the value you want to preserve, not on the entire URL after you have assembled it.

For example, suppose a sharing service expects a target parameter and your destination is https://example.com/search?q=tea & cake. If you paste that destination directly after ?target=, the destination's question mark, equals sign, spaces, and ampersand can be interpreted as URL syntax instead of data. Encode the destination value, then put the encoded result after target=.

RFC 3986 describes percent-encoding as a percent sign followed by two hexadecimal digits for a data octet. It also distinguishes characters that can act as delimiters in a URI. That is why an encoder is useful here: the characters are not inherently bad, but their meaning changes with the URI component that contains them.

Keep separators and data in separate places

A full query string has structure. In https://site.example/?source=newsletter&target=VALUE, the first ? begins the query and the & separates source from target. Those structural characters stay outside the encoded values. The text inside VALUE is what should be encoded when it contains characters that must remain data.

  • Encode a search phrase, redirect URL, title, email subject, or other individual parameter value before joining it to the URL.
  • Do not encode the ?, &, and = separators of a URL you have already deliberately structured.
  • If a value already contains %20 or another percent sequence, decide whether it is already encoded before running it through an encoder again. Encoding an already encoded value can turn % into %25.
  • Use the exact parameter name required by the receiving service. Encoding preserves characters; it does not correct a misspelled field name or an unsupported API option.

The site tool uses JavaScript encodeURIComponent in encode mode and decodeURIComponent in decode mode. It transforms one supplied value; it does not parse a complete URL, choose an API's special serialization rules, or test that a remote endpoint accepts the resulting request. A link can be syntactically tidy and still point to the wrong service or require authentication.

Take a concrete scenario: a newsletter builder needs to pass this destination as a parameter to a redirect page: https://store.example/item?color=blue&size=large. First, put only that destination in encode mode. Copy the encoded output and attach it after the redirect page's target= parameter. Keep the redirect page's own parameters outside the encoded value.

Next, switch the tool to decode mode and paste the exact encoded value you copied. The decoded output should match the destination character for character, including its own ?, &, and =. This is a practical post-processing check: it catches a missing character, a copied separator, or a double-encoded percent sign before the link reaches a campaign, a customer, or an API client.

If your values come from JSON, inspect the source string first with the JSON formatter so that escaped quotes or line breaks are visible. Base64 is not a substitute for URL encoding: it represents data differently and may still contain characters that need handling in a URL context. For sensitive tokens or private destinations, avoid putting them in shareable query strings; an encoder cannot make a URL secret.

Common questions

Should I encode the whole URL at once?

Usually no. Encode the individual data value, then add it to a URL whose query separators you control. Encoding a complete URL can also encode the separators that make the URL work.

Why did %20 become %2520?

That is a common sign of double encoding. %25 is the encoded form of a percent sign, so an already encoded %20 can become %2520 when treated as raw text again. Decode and compare the intended original value before changing the link.

Does an ampersand always need encoding?

An ampersand used as part of a parameter value should be encoded so it is not mistaken for a separator. The ampersand between two completed name=value pairs is structural and should remain outside the values.

Can this tool validate an API request?

No. It encodes or decodes a value locally. It cannot confirm an endpoint, authentication method, request body, service-specific parameter rules, or the response from an API.

Is URL encoding encryption?

No. Percent-encoding is a representation for URI components, not a confidentiality mechanism. Anyone with the URL can decode visible values, so keep secrets and personal data out of shareable links.