A URL encoder and decoder helps you safely prepare query parameters, inspect API requests, and troubleshoot links that break when they contain spaces, symbols, or nested data. This guide explains percent encoding, shows practical JavaScript examples, and provides a reliable workflow for using browser-based URL encoding tools without accidentally changing the meaning of a URL.
Overview
A URL is made of several parts, including a scheme such as https, a host, a path, an optional query string, and sometimes a fragment. For example:
https://example.com/search?q=web%20development&page=2
Here, q and page are query parameters. The space in web development has been percent-encoded as %20. Percent encoding represents a character by its byte value in hexadecimal form, preceded by a percent sign.
Encoding is necessary because URLs have structural characters with special meanings. A question mark can begin a query string, an ampersand can separate parameters, and a hash symbol can begin a fragment. If one of those characters is intended to be data instead of URL structure, it must be encoded.
An online URL encoder is useful when you need to quickly encode a parameter value, verify how a browser or API client will interpret a string, or decode an existing URL during debugging. The important distinction is what you encode: in most cases, encode the individual value rather than the entire URL.
Core framework: encode values, not URL structure
The safest general workflow is to build a URL from known components:
- Keep the scheme, host, and path as URL structure.
- Encode each query parameter value separately.
- Join the encoded parameters with ampersands.
- Inspect the final URL to confirm that separators remain visible.
Suppose an API request needs the search value red shoes & boots. The ampersand belongs inside the value, so it should not be treated as a parameter separator. The resulting query parameter is:
q=red%20shoes%20%26%20boots
The complete URL could be:
https://api.example.com/products?q=red%20shoes%20%26%20boots
If you encode the whole URL instead, characters such as :, /, and ? may also be converted. That can be useful when a URL is being placed inside another parameter, but it will generally make the result unsuitable as a normal standalone request URL.
Reserved and unreserved characters
Some characters are commonly safe in their ordinary roles, while others are reserved because they separate URL components. Characters such as ?, &, =, #, and % deserve particular attention. A literal percent sign is represented as %25, and a literal ampersand inside a value is represented as %26.
Spaces are often shown as %20 in URLs. In form-style query encoding, a space may instead appear as +. These representations can be handled differently by libraries and servers, so use the format expected by the system receiving the request.
JavaScript methods
In JavaScript, use encodeURIComponent() for an individual query parameter or path segment:
const term = "red shoes & boots";
const url = `https://api.example.com/products?q=${encodeURIComponent(term)}`;
console.log(url);
// https://api.example.com/products?q=red%20shoes%20%26%20boots
Use decodeURIComponent() to decode a value that was encoded with the same general approach:
const encoded = "red%20shoes%20%26%20boots";
const decoded = decodeURIComponent(encoded);
console.log(decoded);
// red shoes & boots
For complete URLs, the URL and URLSearchParams APIs are usually clearer than manually concatenating strings:
const url = new URL("https://api.example.com/products");
url.searchParams.set("q", "red shoes & boots");
url.searchParams.set("page", "2");
console.log(url.toString());
This approach keeps parameter names and values separate and lets the platform handle serialization. It also makes it easier to add, replace, or remove one parameter without accidentally damaging the rest of the URL.
Practical examples
Encoding a redirect URL inside another parameter
Nested URLs are a common source of errors. Consider a login route that accepts a destination:
https://example.com/login?returnTo=https://example.com/dashboard?tab=reports
The inner question mark and its parameters can be confused with the outer query string. Encode the complete value of returnTo:
const destination = "https://example.com/dashboard?tab=reports";
const loginUrl = `https://example.com/login?returnTo=${encodeURIComponent(destination)}`;
The result contains an encoded inner URL while preserving the outer URL's structure. This pattern also applies to callback URLs, webhook targets, search links, and API parameters that accept another URL as input.
Decoding an API request during debugging
When an API appears to receive the wrong search term, copy the relevant parameter value and decode it separately. For example, status%3Aopen%20project decodes to status:open project. Check whether the colon, spaces, or other punctuation were intended as data.
For larger payloads, a JSON formatter can help inspect a JSON object after you have decoded it. If the request contains a token in a query parameter, treat it as sensitive data and avoid pasting it into an untrusted service.
Using an online URL encoder
A browser-based URL encoder is most useful for a quick, bounded transformation:
- Identify whether you have a complete URL, a path segment, or a parameter value.
- Paste only the necessary data into the tool.
- Choose encode or decode deliberately; do not assume the operation is reversible when the input has already been transformed multiple times.
- Compare the output with the expected URL structure.
- Test the final request in the same client or environment used by your application.
For scheduled API calls, URL values may also appear inside cron commands or deployment configuration. Keep the URL in a quoted variable where possible, then validate the final command separately. The cron expression guide covers the scheduling side of that workflow.
Common mistakes
Encoding the complete URL when only a value needs encoding
This can turn a usable URL into a string that no longer has recognizable structure. Encode the component that contains user or application data, not the surrounding syntax.
Encoding twice
Double encoding happens when an already encoded value is encoded again. For example, %26 can become %2526 because the percent sign itself was encoded. If a server decodes only once, the application may receive the literal text %26 instead of an ampersand.
To diagnose this, inspect the value at each boundary: browser, frontend code, HTTP client, server framework, and application logic. Decode only as many times as the system's contract requires.
Decoding too early
If you decode a complete URL before parsing its query parameters, encoded separators can become active structure. Parse the URL first, then decode the specific component being inspected. In JavaScript, URLSearchParams is preferable to manually splitting a raw query string in many cases.
Ignoring character encoding
Percent encoding is normally based on UTF-8 for modern web applications. Test values containing accented characters, emoji, or non-Latin scripts when international input matters. A URL encoder that produces unexpected output may be receiving text in a different character encoding or may be operating on already transformed data.
Putting secrets in URLs
Encoding does not encrypt data. Query strings can appear in browser history, logs, analytics systems, referrer data, and monitoring tools. Do not treat a URL encoder or percent encoding as a way to protect passwords, private keys, session credentials, or other secrets.
When to revisit your URL encoding approach
Review your URL handling whenever an API client, server framework, router, proxy, or serialization library changes. A change in any layer can affect whether spaces become %20 or +, when decoding occurs, and whether repeated parameters are preserved.
Revisit the implementation when you add nested URLs, international input, file paths, signed requests, redirect parameters, or new authentication flows. These cases expose assumptions that may remain hidden with simple alphanumeric values.
Keep a small test set in your application or debugging notes. Include a plain word, a value with spaces, a value containing & and =, a nested URL, Unicode text, and an already encoded value. Confirm that each input arrives at the server exactly as intended.
For a practical final check, trace one request from input to server parsing: identify the component being encoded, inspect the serialized URL, decode only the relevant value, and verify the application-level result. This habit is more reliable than repeatedly applying an online URL encoder until the output appears correct.