496+ Tools Comprehensive Tools for Webmasters, Developers & Site Optimization

URL Encoder/Decoder - Encode and Decode URLs

URL Encoder/Decoder

Understanding URL Encoding (Percent Encoding)

What is URL Encoding?

URL encoding, also called percent encoding, is the process of converting characters into a format that can be safely transmitted over the internet in URLs. URLs can only contain a limited set of characters from the ASCII character set. Any character outside this set, or characters with special meaning in URLs, must be encoded as a percent sign followed by two hexadecimal digits representing the character's byte value.

For example, a space character is encoded as %20, an ampersand as %26, and a plus sign as %2B.

Why URL Encoding is Necessary

1. Reserved Characters

Certain characters have special meanings in URLs and must be encoded when used literally:

  • ? (question mark) - Separates path from query string
  • & (ampersand) - Separates query parameters
  • = (equals) - Separates parameter names from values
  • # (hash) - Indicates fragment identifier
  • / (forward slash) - Separates path components
  • : (colon) - Separates scheme from authority
  • @ (at sign) - Separates credentials from hostname

2. Unsafe Characters

Some characters can cause problems or have ambiguous meanings in URLs:

  • Space - Can be encoded as %20 or + in query strings
  • < > (angle brackets) - Can be confused with HTML
  • " (quotes) - Can break HTML attributes
  • { } (curly braces) - Reserved for future URI syntax
  • | \ ^ ~ - Often cause issues with gateways

3. Non-ASCII Characters

Characters from non-English languages, emoji, and special symbols must be encoded. For example:

  • Spanish: niño becomes ni%C3%B1o
  • Chinese: 网页 becomes %E7%BD%91%E9%A1%B5
  • Emoji: 😀 becomes %F0%9F%98%80

Common Encoding Examples

Character Encoded Description
Space %20 or + Plus sign used in query strings
! %21 Exclamation mark
# %23 Hash/pound sign
$ %24 Dollar sign
% %25 Percent sign itself
& %26 Ampersand
' %27 Apostrophe
( %28 Left parenthesis
) %29 Right parenthesis
+ %2B Plus sign
/ %2F Forward slash
: %3A Colon
= %3D Equals sign
? %3F Question mark
@ %40 At symbol

When to Use URL Encoding

1. Query String Values

Always encode values in query strings, especially when they contain special characters or spaces:

Wrong: /search?q=cats and dogs

Correct: /search?q=cats%20and%20dogs

2. Path Components

When path segments contain special characters, they should be encoded:

Example: /files/my%20document.pdf instead of /files/my document.pdf

3. Form Data

When submitting forms with GET method, form fields are automatically URL-encoded by the browser. Understanding this helps debug form submission issues.

4. API Requests

When building API request URLs programmatically, ensure all dynamic values are properly encoded to prevent errors and security vulnerabilities.

URL Encoding in Different Contexts

Application/x-www-form-urlencoded

This is the default encoding for HTML form data. It uses + for spaces instead of %20 and encodes most special characters.

URI Component Encoding

In JavaScript, encodeURIComponent() encodes all characters except: A-Z a-z 0-9 - _ . ! ~ * ' ( )

Full URI Encoding

encodeURI() encodes a complete URI, preserving characters like :, /, ?, and & that have special meaning in URIs.

Security Considerations

1. Preventing Injection Attacks

Always encode user input before including it in URLs to prevent URL injection attacks. Attackers might try to inject malicious query parameters or manipulate the URL structure.

2. Avoiding Double Encoding

Be careful not to encode data multiple times, which can lead to incorrect values. For example, a space encoded twice becomes %2520 instead of %20.

3. Sensitive Data

URL encoding is NOT encryption. Never put sensitive information like passwords in URLs, even if encoded. URLs are logged by servers, visible in browser history, and transmitted in plain text.

Best Practices

  • Use Libraries: Use built-in URL encoding functions in your programming language rather than manually encoding
  • Encode Early: Encode values when building URLs, not when displaying them
  • Decode Once: Decode URL parameters once when receiving them, then work with decoded values
  • Validate After Decoding: Always validate and sanitize decoded values before using them
  • International Support: Use UTF-8 encoding for international characters to ensure compatibility
  • Test Edge Cases: Test your URL handling with special characters, spaces, and non-ASCII text

Common Pitfalls

1. Plus Sign Confusion

In query strings, + represents a space, but in paths it's a literal plus sign. Context matters when encoding and decoding.

2. Fragment Identifiers

Fragment identifiers (after #) are not sent to the server, so server-side encoding doesn't affect them. They're handled entirely by the browser.

3. Path Separators

Forward slashes in path components should usually be encoded as %2F to avoid being interpreted as path separators.

Use Cases for This Tool

  • Encode search terms or form data for URL parameters
  • Decode URL-encoded strings to see original values
  • Debug issues with special characters in URLs
  • Prepare data for API requests with query parameters
  • Learn how different characters are encoded
  • Test URL handling in your web applications
  • Create shareable links with special characters