BuildUtilities

URL Encoding Guide

What is URL Encoding?

URL encoding (percent encoding) replaces unsafe characters with a % followed by two hexadecimal digits. For example, a space becomes %20. This ensures URLs are valid and can be transmitted safely.

Common Encoded Characters

CharacterEncodedPurpose
(space)%20Spaces in URLs
&%26Parameter separator
=%3DKey-value assignment
#%23Fragment identifier
/%2FPath separator

Code Examples

// JavaScript
encodeURIComponent("hello world & more") // "hello%20world%20%26%20more"
decodeURIComponent("hello%20world")      // "hello world"

// encodeURI vs encodeURIComponent
encodeURI("https://example.com/path?q=hello world")
// "https://example.com/path?q=hello%20world"

encodeURIComponent("https://example.com/path")
// "https%3A%2F%2Fexample.com%2Fpath"

Common Mistakes

  • Double encoding: Encoding an already-encoded string gives %2520 instead of %20.
  • Using encodeURI for query values: Use encodeURIComponent for individual parameter values.
  • + vs %20: In query strings, + represents a space (form encoding), but in paths only %20 is valid.

Encode and decode URLs with our URL Encoder/Decoder. Parse query parameters with the Query String Parser.

FAQ

What's the difference between encodeURI and encodeURIComponent?

encodeURI encodes a full URI, preserving :, /, ?, #. encodeURIComponent encodes everything except alphanumeric and - _ . ~ characters.

Try These Tools

Related Documentation

Tip Jar