Encoding5 min read

URL Encoding: Encode Query Values Without Breaking a URL

URL encoding is often needed when text is inserted into a query parameter or another part of a URL. The key is to encode the value that belongs in that position while preserving the separators that define the URL structure.

What percent-encoding is for

Percent-encoding represents a character using a percent sign followed by hexadecimal byte values. It is used when a URL component contains characters that need to be represented as data rather than interpreted as URL syntax.

For example, a space in a component is represented as %20. Characters such as ampersand, equals sign, and question mark can also be encoded when they are part of a value.

Component textEncoded component
hello worldhello%20world
a&ba%26b
price=10?price%3D10%3F

Encode a value, not the complete URL

A complete URL has structural characters such as the scheme separator, path slashes, query marker, parameter separators, and fragment marker. If the complete address is encoded as one component, those structural characters are encoded too, so the result no longer has the same URL structure.

Instead, keep the URL structure in place and encode each dynamic value separately before inserting it into the appropriate position.

Build a query parameter from a search value

Search text: shoes & bags
Encoded value: shoes%20%26%20bags

URL structure:
https://example.com/search?q=shoes%20%26%20bags

Component encoding and form encoding are not identical

JavaScript encodeURIComponent encodes an individual component and represents a space as %20. Some HTML form-encoding workflows use a plus sign (+) for spaces. That difference matters when a receiving server expects form-encoded data rather than a percent-encoded component.

Choose the encoding format required by the API or form you are using. Do not replace %20 with +, or the reverse, without checking the receiving system's rules.

Decoding and common errors

Decoding reverses percent-encoded component text. The input must contain valid percent escapes and valid encoded byte sequences. An incomplete escape, such as a percent sign without two hexadecimal digits, can cause decoding to fail.

Decode only the component you intend to interpret. Decoding an entire URL indiscriminately can turn encoded data characters back into URL separators and change how the address is parsed.

  • Check that every percent sign is followed by two hexadecimal digits.
  • Confirm whether the value uses component encoding or form encoding.
  • Do not decode a query parameter more times than the format requires.
  • Avoid placing passwords, access tokens, or other secrets in URLs; addresses can appear in browser history, server logs, and analytics systems.

Using the KitDevTools URL Encoder / Decoder

The online tool uses JavaScript encodeURIComponent and decodeURIComponent. It is intended for individual URL components or text values, supports input up to 100,000 characters, and runs in the browser. It is not a URL parser or a complete-URL validator.

Related Tools

Your privacy matters

We use optional analytics cookies to understand how our tools are used and improve your experience. These controls apply to Google Analytics only, not advertising preferences. Privacy Policy