{ }
中文

URL Encoder / Decoder

Encode or decode URLs and query string parameters.

URL Encoding Explained

URL encoding (also called percent-encoding) replaces unsafe characters with a percent sign followed by two hexadecimal digits that represent the character's UTF-8 byte. Reserved characters that have a special meaning in URLs — such as / ? # & = + space — must be percent-encoded when they appear inside a path segment or a parameter value rather than as a delimiter.

JavaScript exposes two built-in helpers. encodeURIComponent encodes everything except A–Z, a–z, 0–9, and the unreserved characters - _ . ! ~ * ' ( ). It is the right choice for a single query parameter value because it preserves no URL structure. encodeURI is more permissive: it leaves URI-structural characters such as : / ? # & untouched, so it is appropriate for whole URLs that already contain valid structure.

This tool wraps both functions and handles failure gracefully. If you paste a malformed percent sequence (for example a stray %Z), the decoder returns an explanatory error rather than throwing. Non-ASCII characters such as Chinese, Japanese, or emoji are first converted to UTF-8 bytes before encoding, which is the modern standard adopted by every major browser.

Use cases

  • Build query strings that include spaces, symbols, or non-ASCII characters.
  • Decode a logged URL to see what a user actually submitted.
  • Safely pass a redirect target as a query parameter.
  • Debug issues where servers receive unexpected characters.
  • Generate clean OAuth callback URLs that include a state parameter.

Best practices

  • Use encodeURIComponent for individual parameter values, not for entire URLs.
  • Encode space as %20 in URL paths; only application/x-www-form-urlencoded bodies use + for space.
  • Encode user-controlled values before concatenating them into a URL to prevent injection.
  • Remember that the # fragment is never sent to the server, so credentials should not live there even encoded.

Frequently asked questions

What is the difference between encodeURI and encodeURIComponent?
encodeURI preserves URI-structural characters like : / ? # &, so it is appropriate for whole URLs. encodeURIComponent encodes those characters too, so it is the right choice for a single query parameter value.
Why is a space encoded as %20 sometimes and + other times?
%20 is the standard percent-encoding for a space. The + form is a legacy rule specific to the application/x-www-form-urlencoded body format used by HTML forms.
Do I need to encode Chinese characters?
Yes. Non-ASCII characters must be UTF-8 encoded and then percent-encoded to travel through URLs reliably. This tool handles that automatically.
Why does decoding fail with "malformed URI sequence"?
The input contains a percent sign that is not followed by two valid hex digits. Either escape the literal % as %25 or fix the surrounding bytes.