ToolRun
🔗

URL Encoder / Decoder

Encode or decode URL components using percent-encoding. Essential for working with query strings, API parameters, and special characters in URLs.

URL Encoder / Decoder

Encode or decode URL components using percent-encoding.

About URL Encoding

URL encoding, also known as percent-encoding, is a mechanism for converting characters into a format that can be safely transmitted in a URL. URLs can only contain a limited set of characters from the ASCII character set. Characters outside this set, or characters with special meaning in URLs (like &, =, ?, and #), must be encoded.

How Percent-Encoding Works

When a character needs to be encoded, it is replaced with a percent sign (%) followed by its two-digit hexadecimal ASCII value. For example:

  • A space becomes %20 (or + in form data)
  • An ampersand (&) becomes %26
  • A question mark (?) becomes %3F
  • A forward slash (/) becomes %2F
  • Non-ASCII characters like emoji or accented letters are first encoded as UTF-8 bytes, then each byte is percent-encoded

When to Use URL Encoding

You need URL encoding in these situations:

  • Query parameters: When passing user input in URL query strings, encoding prevents special characters from breaking the URL structure.
  • API requests: RESTful API endpoints often require encoded parameters, especially for search queries or filter values.
  • Form submissions: HTML forms with GET method encode field values in the URL automatically, but you may need manual encoding for AJAX requests.
  • File paths: Filenames with spaces or special characters need encoding when used in URLs.

encodeURIComponent vs encodeURI

JavaScript provides two encoding functions with important differences:

  • encodeURIComponent() encodes everything except: A-Z, a-z, 0-9, - _ . ! ~ * ' ( ). Use this for encoding individual query parameter values.
  • encodeURI() preserves URL-structural characters like :, /, ?, #, and &. Use this for encoding an entire URL while keeping its structure intact.

This tool uses encodeURIComponent, which is the correct choice for encoding individual values that will be placed into URLs.

Frequently Asked Questions

Why do I need to URL-encode special characters?
URLs have a specific syntax where certain characters have special meaning. The ? separates the path from query parameters, & separates parameters, = separates keys from values, and # indicates a fragment. If your data contains these characters, they must be encoded so the browser or server interprets them as data rather than URL structure. Without encoding, a search query like "cats & dogs" would break the URL parameter structure.
What is the difference between %20 and + for spaces?
Both represent a space, but in different contexts. %20 is the standard percent-encoding for a space and is used in URL paths and most contexts. The + sign represents a space only in the application/x-www-form-urlencoded format, which is used by HTML form submissions with the GET method. When encoding URL components (query parameters), %20 is the technically correct encoding, though most servers accept + as well.
Is URL encoding the same as HTML encoding?
No, they are different. URL encoding (percent-encoding) converts characters to %XX format for safe transmission in URLs. HTML encoding converts characters to HTML entities (like &amp;amp; for & or &amp;lt; for <) for safe display in HTML documents. They serve different purposes: URL encoding ensures valid URLs, while HTML encoding prevents cross-site scripting (XSS) and ensures characters display correctly in web pages.
Can I encode an entire URL at once?
You should generally encode individual components (parameter values) rather than the entire URL. Encoding a full URL would break its structure by encoding characters like :, /, and ? that have special URL meaning. For example, encoding "https://example.com" would produce "https%3A%2F%2Fexample.com", which is no longer a valid URL. Encode only the variable parts, like query parameter values.

Related Tools