' + '

URL Encode/Decode

Encode and decode URL components

When URL Encoding Is Required

URLs are restricted to a safe subset of ASCII characters. Spaces, special characters, and non-ASCII characters must be percent-encoded as %XX where XX is the byte value in hexadecimal. The space character becomes %20 (or + in query strings). An ampersand in a query parameter value must be encoded as %26 or it will be interpreted as a parameter separator.

encodeURIComponent vs. encodeURI

JavaScript provides two functions with different scopes:

Common Encoding Mistakes

Plus Sign in Query Strings

In application/x-www-form-urlencoded format (HTML form submissions), + represents a space, and %2B represents a literal plus sign. In URL path segments, + is a literal plus, not a space. This mismatch is a common source of decoding bugs in web frameworks.