URLSearchParams builds query strings using form-style encoding. It encodes reserved characters safely, but it represents spaces as +, which can surprise developers expecting %20.
Use the URL Encode tool to compare manual component encoding with form-style output, and the URL Decode tool to inspect the results.
What does URLSearchParams encode?
URLSearchParams encodes query parameter names and values so they can be safely placed after ?. It encodes characters such as &, =, %, and literal plus signs, while using + for spaces because it follows form-encoded query rules.
Why does URLSearchParams use + for spaces?
URLSearchParams uses + for spaces because query strings built from form data historically use application/x-www-form-urlencoded rules. In that format, a space is represented by +, and a literal plus sign must be encoded as %2B.
Is URLSearchParams safe for user input?
Yes. URLSearchParams is safe for ordinary query parameter names and values because it handles escaping for you. It is much safer than concatenating ?q= plus raw user text, especially when the text contains ampersands or equals signs.
Does URLSearchParams encode slashes?
URLSearchParams encodes slashes when they appear inside query parameter values. That is correct, because a slash inside a value is data, not a path separator. A nested URL carried as a query value will therefore have its slashes encoded.
How do I decode URLSearchParams output?
Use URLSearchParams itself, your framework's query parser, or a form-aware decoder. Plain decodeURIComponent does not convert + to a space, so manually decoding the raw query string can give misleading results.
Should I use URLSearchParams or encodeURIComponent?
Use URLSearchParams when building a full query string from names and values. Use encodeURIComponent when you need to encode one component directly. Both are useful, but URLSearchParams reduces mistakes around separators.
How can I inspect the exact output?
Copy the query value or full query string and inspect it with the URL Decode tool. If a plus sign should remain a plus, make sure the encoded form contains %2B rather than a raw +.