URL Encoder

Encode text for safe URL transmission

Convert text to URL encoded format. This tool is useful for encoding URLs, query parameters, or other web content that needs to be safely transmitted.

Input Text

URL Encoded Output

encodeURIComponent

Encode your text to see results

Common URL Encoding Use Cases

Search Query Parameters

Original: search?query=how to build websites
Encoded: search?query=how%20to%20build%20websites

Spaces in search queries must be encoded to prevent URL parsing issues.

Characters Reserved in URLs

Original: product?name=T&T Special#2
Encoded: product?name=T%26T%20Special%232

Characters like &, #, and spaces have special meaning in URLs and must be encoded.

International Characters

Original: location=München
Encoded: location=M%C3%BCnchen

Non-ASCII characters are encoded using UTF-8 byte sequences.

Form Data Submission

Original: email=user@example.com
Encoded: email=user%40example.com

Email addresses contain @ symbols that need encoding in query parameters.

JSON Data in URLs

Original: data={"name":"John","age":30}
Encoded: data=%7B%22name%22%3A%22John%22%2C%22age%22%3A30%7D

JSON objects contain many special characters that require encoding.

File Paths with Spaces

Original: download.php?file=My Document.pdf
Encoded: download.php?file=My%20Document.pdf

File names with spaces need encoding for proper URL handling.

Complex Query Strings

Original: api.php?filters=status:active,date>2023-01-01
Encoded: api.php?filters=status%3Aactive%2Cdate%3E2023-01-01

Complex filter expressions often contain special characters.

Social Media Sharing

Original: share?text=Check this out! 🚀
Encoded: share?text=Check%20this%20out%21%20%F0%9F%9A%80

Social sharing URLs often contain text with emojis and punctuation.

💡 Pro Tips:

  • • Use encodeURIComponent() for individual parameter values
  • • Use encodeURI() for complete URLs that should remain functional
  • • Always encode user input before adding it to URLs
  • • Test your URLs with international characters and special symbols
  • • Remember that spaces can be encoded as either %20 or + depending on context

What is URL Encoding?

URL encoding, also known as percent-encoding, is a mechanism for encoding information in a Uniform Resource Identifier (URI) under certain circumstances.

URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits. URLs can only be sent over the Internet using the ASCII character-set. URL encoding is used to convert non-ASCII characters to a format that can be transmitted over the Internet.

URL encoding is essential for creating valid URLs and for sending form data in HTTP requests, especially when handling special characters, spaces, and international characters.

encodeURI vs. encodeURIComponent

encodeURI

  • Encodes a complete URI
  • Does not encode: A-Z a-z 0-9 - _ . ! ~ * ' ( )
  • Also doesn‘t encode: ; / ? : @ & = + $ , #
  • Use for encoding a full URL
  • Example: https://example.com/path?name=John%20Doe

encodeURIComponent

  • Encodes a URI component (like query parameter)
  • Does not encode: A-Z a-z 0-9 - _ . ! ~ * ' ( )
  • Encodes: ; / ? : @ & = + $ , #
  • Use for encoding parameter values
  • Example: name=John%20Doe&data=a%3Db%26c%3Dd

Understanding URL Encoding

Why is URL Encoding Important?

URL encoding is crucial for web development because URLs have a limited character set. They can only contain certain ASCII characters, and special characters must be encoded to prevent them from being interpreted as URL delimiters or causing parsing errors.

Data Integrity: Ensures special characters are transmitted correctly

Security: Prevents URL injection attacks and parsing errors

Compatibility: Ensures URLs work across different systems and browsers

International Support: Allows non-ASCII characters in URLs

Common Characters That Need Encoding

Reserved Characters

Space%20
!%21
"%22
#%23
$%24
%%25
&%26
%27

Special Characters

(%28
)%29
+%2B
,%2C
/%2F
:%3A
;%3B
=%3D

When to Use Each Method

Use encodeURI() when:

  • Encoding a complete URL that you want to remain functional
  • The URL contains path separators, query strings, or fragments that should remain unencoded
  • You‘re encoding a full URL for storage or transmission
  • Example: Converting a URL with spaces in the path

Use encodeURIComponent() when:

  • Encoding individual parameters or values in a URL
  • The data contains characters that have special meaning in URLs
  • Building query strings dynamically
  • Example: Encoding form data before adding to a query string

Best Practices

Always encode user input: Never trust user-provided data in URLs without encoding

Choose the right method: Use encodeURIComponent() for parameters, encodeURI() for full URLs

Double encoding: Be careful not to encode already encoded strings

Server-side validation: Always validate and sanitize on the server side as well

Test thoroughly: Test with various character sets including international characters

Real-World Applications

Web Development

  • Building dynamic URLs with parameters
  • Encoding form data for GET requests
  • Creating safe download links
  • Social media sharing URLs

API Integration

  • Query parameter encoding for API calls
  • OAuth redirect URL construction
  • Search API query encoding
  • Webhook URL parameter handling