BytePane

URL Encode & Decode

Encode special characters for URLs or decode percent-encoded strings back to readable text.

About URL Encoding

URL encoding (percent-encoding) is defined in RFC 3986 and is essential for transmitting data safely in URLs. Characters outside the ASCII set, reserved characters like &, =, ?, and spaces must be encoded to prevent ambiguity in URL parsing. Every web browser, server, and API framework relies on percent-encoding to handle special characters correctly.

URL Encoding Quick Reference

CharacterEncodedUse Case
space%20 or +Search queries, file names
&%26Query parameter separator
=%3DKey-value assignment in params
/%2FPath segment separator
#%23Fragment identifier

encodeURI vs encodeURIComponent

Use encodeURIComponent() for individual query parameters — it encodes everything except letters, digits, and a few safe characters (- _ . ~). Use encodeURI() only when encoding a complete URL where you want to preserve the structure characters like :, /, ?, and #. In practice, encodeURIComponent() is used far more frequently because most encoding happens at the parameter level. Misusing encodeURI() on query values is one of the most common URL encoding bugs in web applications.

Common URL Encoding Mistakes

Double-encoding happens when already-encoded text gets encoded again, turning %20 into %2520. This is the #1 URL encoding bug in production systems. Always decode first if you're unsure whether input is already encoded. Encoding the entire URL instead of just the query parameters breaks the protocol, host, and path separators. Forgetting to encode form data causes silent failures when users input special characters in forms submitted via GET requests.

Frequently Asked Questions

What is URL encoding?

URL encoding (also called percent-encoding) converts special characters into a format that can be safely transmitted in URLs. Characters like spaces, &, =, ?, and non-ASCII characters are replaced with a % followed by their hexadecimal value. For example, a space becomes %20.

What is the difference between encodeURI and encodeURIComponent?

encodeURI() encodes a complete URI, preserving characters like :, /, ?, #, &, and =. encodeURIComponent() encodes everything except letters, digits, and - _ . ~ making it suitable for encoding individual query parameters or path segments.

When should I use URL encoding?

Use URL encoding when passing special characters in query strings, form data, path segments, or any part of a URL that might contain spaces or special characters. Most programming languages and frameworks handle this automatically.

Related Tools