URL Encode/Decode

Encode text for safe URL usage by converting special characters to percent-encoded sequences, or decode percent-encoded URLs back to readable text.

Ad Space

How URL Encoding and Decoding Works

URL encoding (also known as percent-encoding) replaces unsafe or reserved characters in URLs with a percent sign (%) followed by two hexadecimal digits representing the character's ASCII value. For example, a space becomes %20, an ampersand becomes %26, and a forward slash becomes %2F. This tool uses the JavaScript encodeURIComponent() function for encoding and decodeURIComponent() for decoding.

Encoding Rules

encodeURIComponent() encodes all characters except: A-Z, a-z, 0-9, hyphen (-), underscore (_), period (.), exclamation mark (!), tilde (~), asterisk (*), single quote ('), and parentheses ( ). Every other character is converted to its UTF-8 byte sequence, with each byte represented as %XX in hexadecimal.

Why URL Encoding Is Necessary

URLs can only contain a limited set of characters defined in RFC 3986. Characters like spaces, ampersands, equals signs, question marks, and hash symbols have special meanings in URLs. If you want to include these characters as data (for example, in a query parameter value), you must encode them to prevent them from being interpreted as URL structure.

Without proper URL encoding, a search query containing an ampersand would break the URL parameter parsing. A filename with spaces would be truncated. A user input containing special characters could lead to broken links, security vulnerabilities, or incorrect data being sent to the server. URL encoding ensures that data is transmitted accurately regardless of its content.

Common Characters and Their Encoded Forms

Here are the most frequently encoded characters: space becomes %20 (or + in form data), ampersand (&) becomes %26, equals (=) becomes %3D, question mark (?) becomes %3F, hash (#) becomes %23, forward slash (/) becomes %2F, plus (+) becomes %2B, at sign (@) becomes %40, and colon (:) becomes %3A. Unicode characters are encoded as multiple %XX sequences representing their UTF-8 bytes.

encodeURIComponent vs. encodeURI

JavaScript provides two encoding functions. encodeURIComponent() encodes everything except unreserved characters, making it suitable for encoding individual URL components like query parameter values. encodeURI() preserves URL structure characters like colons, slashes, and question marks, making it suitable for encoding entire URLs. This tool uses encodeURIComponent() because it is the safer and more commonly needed option.

Double Encoding Issues

A common bug in web applications is double encoding, where an already-encoded string is encoded again. For example, %20 (encoded space) becomes %2520 when double-encoded. This tool can help you detect double encoding by decoding a URL and checking if the result still contains percent-encoded sequences, indicating the original was double-encoded.

Use Cases for URL Encoding

Developers use URL encoding when building URLs with query parameters, when passing data through URL fragments, when creating bookmarkable search result pages, when encoding filenames in download URLs, and when debugging URL-related issues in web applications. It is also essential when constructing OAuth callback URLs and API endpoints that include user-provided data.

Privacy Notice

All encoding and decoding happens entirely in your browser. No data is transmitted to any server.

Frequently Asked Questions

What is the difference between encodeURI and encodeURIComponent?

encodeURI preserves URL structure characters like :, /, ?, and # while encoding other unsafe characters. encodeURIComponent encodes everything except unreserved characters (A-Z, a-z, 0-9, -, _, ., !, ~, *, ', (, )). Use encodeURIComponent for individual parameter values and encodeURI for complete URLs.

Why does a space become %20 in URLs?

The space character (ASCII code 32, hexadecimal 20) is not allowed in URLs. Percent-encoding replaces it with %20, which is the percent sign followed by the hexadecimal representation of the character code. In HTML form submissions, spaces may also be encoded as + characters.

What is double encoding and how do I fix it?

Double encoding happens when an already-encoded string is encoded again, turning %20 into %2520. To fix it, decode the string once. If the result still contains percent-encoded sequences, decode again. This tool can help you detect and fix double encoding.

Is my data sent to a server?

No. All encoding and decoding happens entirely in your browser using JavaScript. Your data never leaves your machine.

Does URL encoding support Unicode characters?

Yes. Unicode characters are first converted to their UTF-8 byte sequence, then each byte is percent-encoded. For example, a Chinese character might become three percent-encoded bytes like %E4%B8%AD.