🧰Online Tools

URL Encoder/Decoder

Encode and decode URL strings

Tips:

  • encodeURIComponent: Encodes all special characters, suitable for URL parameters
  • encodeURI: Preserves URL structure characters (: / ? # etc.), suitable for complete URLs

About This Tool

URL encoding (also called percent-encoding) is a method to convert special characters into a format that can be safely transmitted in URLs. Non-ASCII characters and URL reserved characters are converted to percent sign (%) followed by two hexadecimal digits. This tool supports two encoding modes: encodeURIComponent for encoding URL parameters, and encodeURI for encoding complete URLs. It supports Chinese and various special character processing, all operations are done locally in your browser.

How to Use

  1. Select encoding mode: encodeURIComponent (recommended for URL parameters) or encodeURI (for complete URLs)
  2. Enter the content you want to encode in the 'Original Text' box
  3. Click 'Encode' button to perform URL encoding
  4. Or paste a URL encoded string in the 'Encoded Result' box
  5. Click 'Decode' button to restore original text
  6. Use 'Copy' button to copy results to clipboard

Common Use Cases

  • URL parameter processing: Encode query string parameters
  • Chinese links: Handle URL addresses containing Chinese
  • Form submission: URL encode form data
  • API calls: Build API requests containing special characters
  • Redirect links: Encode redirect URLs
  • Link sharing: Handle links containing spaces or special characters

FAQ

Q1: What's the difference between encodeURI and encodeURIComponent?

encodeURIComponent encodes all special characters (including / ? # & = etc.), suitable for encoding URL query parameter values. encodeURI preserves URL structure characters without encoding, suitable for encoding complete URLs. For example, if a parameter value contains &, you must use encodeURIComponent.

Q2: Why does Chinese in URLs become garbled?

It's not garbled, it's the normal result of URL encoding. Chinese characters are converted to %XX format for each byte after UTF-8 encoding. For example, '你' in UTF-8 is E4BDA0, URL encoded becomes %E4%BD%A0. Browsers and servers automatically decode to restore it.

Q3: Should spaces be encoded as %20 or +?

In URL paths and query parameters, spaces should be encoded as %20. Plus sign (+) representing space is an older convention from form submission (application/x-www-form-urlencoded). This tool uses standard %20 encoding.

Q4: Which characters need URL encoding?

Besides letters, numbers, and - _ . ~ characters, all other special characters should be encoded. Chinese, Japanese, and other non-ASCII characters must be encoded. Even though modern browsers can use Chinese URLs directly, encoded links have better compatibility.

Q5: What if decoded result is garbled?

The original encoding may have used a non-UTF-8 character set (like GBK). This tool uses UTF-8 decoding, so other encodings will show garbled text. In this case, you need to re-encode with the corresponding character set.