Use this URL encoder and decoder checklist to construct reliable links, preserve query parameters, handle spaces and Unicode, and troubleshoot broken redirects or API requests without encoding the wrong part of a URL.
Overview
URL encoding, more precisely percent-encoding, represents characters that have a special meaning in a URL or cannot be transmitted safely in their original form. A space may become %20; an ampersand inside a search value may become %26; and a non-ASCII character may be represented by one or more UTF-8 byte sequences.
The important rule is to encode each URL component according to its role. A complete URL is not the same thing as a path segment, a query parameter value, a fragment, or form data. Encoding the entire URL as if it were one value can turn separators such as :, /, ?, and & into data and make the result unusable.
When using an online URL encoder, first decide what you are encoding. For a query value, encode only the value. For a path value, encode only the segment that will be inserted into the path. For an already assembled URL, parse and modify its components rather than applying a generic encoder to the entire string.
This component-based approach is useful in browser applications, API clients, redirect handlers, logging tools, and command-line workflows. If the URL is part of a larger API debugging problem, pair this checklist with a repeatable HTTP status code debugging workflow and validate the expected request shape against the API contract.
Checklist by scenario
Building a complete URL
- Keep the scheme, host, port, path, query, and fragment structurally separate.
- Do not percent-encode the scheme separator or host delimiters.
https://example.commust remain structurally recognizable. - Encode dynamic values before inserting them into a component.
- Parse an existing URL with the platform URL API when possible instead of editing separators with string replacement.
In JavaScript, a safe pattern is to use URL and URLSearchParams:
const url = new URL("https://example.com/search");
url.searchParams.set("q", "red & blue");
url.searchParams.set("page", "2");
console.log(url.toString());
// https://example.com/search?q=red+%26+blue&page=2
The exact serialization of a space can depend on the component and API. In this example, URLSearchParams uses the form-style convention of + for a space. The ampersand in the search term is encoded, so it cannot be mistaken for the separator between parameters.
Encoding a query parameter value
- Encode the value, not the parameter name-and-value pair as one undifferentiated string.
- Let the query serializer add separators between parameters.
- Use a query-aware API when values may contain spaces, ampersands, equals signs, question marks, Unicode, or repeated fields.
For a single JavaScript value, encodeURIComponent() is commonly appropriate:
const term = "red & blue";
const url = "/search?q=" + encodeURIComponent(term);
// /search?q=red%20%26%20blue
For multiple fields, prefer URLSearchParams so that separators, repeated keys, and serialization are handled consistently:
const params = new URLSearchParams({
q: "red & blue",
sort: "newest"
});
const query = params.toString();
Encoding a path segment
A path is hierarchical. Its slashes separate segments, so a slash that belongs inside a user-provided name must be encoded rather than treated as another directory boundary.
const fileName = "reports/2026 final.pdf";
const url = "/files/" + encodeURIComponent(fileName);
// /files/reports%2F2026%20final.pdf
Use this approach when the value represents one segment. If the input intentionally represents several path segments, split and encode each segment separately. Do not blindly encode a whole path if its existing slashes are meaningful structure.
Handling an anchor fragment
A fragment follows # and is generally used by the client side of an application. It is not sent to the server in the HTTP request. Encode dynamic fragment content according to how the application reads it, and do not assume that server-side routing will receive the fragment.
Encoding form data
application/x-www-form-urlencoded form data has conventions that differ from a generic component encoder. In this format, spaces are commonly serialized as plus signs. A literal plus sign must therefore be encoded so it is not interpreted as a space.
For example, the value C++ should not be manually changed to C++ in form data and then decoded as though every plus were literal. Use a form-aware serializer, or make sure the encoder represents the plus sign as %2B. This distinction is especially important when handling search forms, callback parameters, and legacy application endpoints.
What to double-check
Spaces and plus signs
There are two common representations for a space: %20 and +. The correct choice depends on the URL component and the parser receiving it. In a query string, a form-style parser may turn + into a space. A generic percent decoder may not. Never replace spaces with plus signs manually unless you are deliberately producing form-encoded data.
Ampersands and equals signs
An ampersand normally separates query parameters, while the first equals sign separates a name from its value. If either character is part of a value, encode it. A value such as color=red&blue must be serialized so the ampersand remains data rather than creating an unexpected parameter.
Unicode and character encoding
Check the characters before and after encoding. URL APIs generally serialize text using UTF-8-based percent-encoding, but a downstream system may apply its own parsing rules. Test accented characters, emoji, non-Latin scripts, and combining characters when they are valid inputs for your application.
Reserved characters
Characters such as ?, #, /, :, and @ can have structural meaning. Whether they should remain visible or be encoded depends on the component. A question mark starting a query is structure; a question mark inside a query value is data and should normally be encoded.
Decode only at the correct boundary
Decode values once, at the point where your application knows what the value represents. Repeated decoding can turn encoded delimiters into active syntax. If a parameter is expected to contain a URL, parse the outer request first, then decode and validate the inner URL according to its intended use.
Privacy and sensitive inputs
Do not paste passwords, session identifiers, private customer data, access tokens, or signed URLs into an online URL encoder unless the tool's handling is appropriate for that data. A browser-based coding utility is convenient for sample values and non-sensitive debugging, but local code or a trusted development environment is preferable for confidential inputs. The same caution applies when inspecting tokens; a JWT decoder workflow should distinguish inspection from verification and avoid exposing live credentials.
Common mistakes
- Encoding the full URL. This often converts structural separators into data. Encode the component that contains user or application data instead.
- Encoding too early. If a value is encoded, concatenated, and encoded again, percent signs can become
%25. Track whether each value is raw or already encoded. - Decoding too early. Decoding a complete request before parsing it can expose encoded separators and change its structure.
- Confusing a plus sign with a space. The interpretation depends on the parser and media type. Test a literal plus sign explicitly.
- Using a query encoder for a path. Query and path components have different structural rules, particularly around slashes.
- Trusting visual appearance. A URL can look plausible while containing an extra parameter, a truncated fragment, or a double-encoded value. Inspect the parsed components and the actual request.
- Skipping boundary tests. Test empty values, repeated keys, ampersands, equals signs, spaces, Unicode, literal plus signs, and percent signs before shipping a URL-building change.
When a request fails, compare the intended value with the raw URL, the parsed parameter map, and the server's interpreted value. This three-step comparison usually reveals whether the problem occurred during construction, transport, or decoding. For related structured payload problems, a JSON formatter and validator can help separate malformed data from a URL transport issue.
When to revisit
Return to this checklist whenever a feature begins accepting a new kind of input, changes from path-based routing to query parameters, adds redirects, or integrates with an API that uses a different form or parsing convention. Revisit it before a release that changes URL construction, serialization libraries, router behavior, or browser-side request code.
Also review the workflow when a previously reliable link starts producing missing parameters, unexpected spaces, redirect loops, signature mismatches, or different behavior between a browser, an API client, and a command-line tool. Capture a representative set of raw inputs and expected parsed outputs, then turn them into automated tests.
Before shipping, use this final action list:
- Identify whether the input is a full URL, path segment, query value, fragment, or form field.
- Choose a component-aware browser API or library.
- Encode each dynamic value exactly once.
- Test spaces, plus signs, ampersands, equals signs, slashes, percent signs, and Unicode.
- Inspect the final URL and the parsed values at the receiving boundary.
- Keep sensitive data out of public or untrusted online tools.
That habit makes an online URL encoder a useful verification aid rather than a substitute for understanding the URL structure your application is producing.