URL Encoder/Decoder

Encode and decode URL strings instantly.

Enter text

Text will be URL encoded (percent encoding)

What is URL Encoding?

URL encoding, also known as percent encoding, is a mechanism for encoding information in a Uniform Resource Identifier (URI). It ensures that special characters and non-ASCII characters can be safely transmitted in URLs without breaking the URL structure or causing parsing errors.

The encoding uses a percent sign (%) followed by two hexadecimal digits. For example, a space character becomes %20, and the @ symbol becomes %40. This format is defined in RFC 3986, the standard for URI syntax.

RFC 3986 specifies which characters are 'reserved' (have special meaning in URLs) and which are 'unreserved' (safe to use without encoding). Reserved characters must be encoded when used in parts of a URL where they have special meaning.

When to Use URL Encoding

URL encoding is essential in several scenarios:

  • Query parameters: Values in URL query strings (after ?) must be encoded to handle spaces, special characters, and non-ASCII text
  • Path segments: When URLs contain user-generated content or file names with special characters
  • Special characters: Characters like &, =, ?, #, and spaces have special meaning in URLs and must be encoded
  • International characters: Non-ASCII characters like é, ñ, or Chinese characters must be encoded using UTF-8 percent encoding
  • HTML forms: Form data submitted via GET method is automatically URL encoded in the query string

URL Encoding Rules

Understanding which characters need encoding helps you create valid URLs:

A-Z, a-z, 0-9Never encoded - safe to use as-is
- _ . ~Never encoded - these characters are safe in URLs
! * ' ( ) ; : @ & = + $ , / ? # [ ]Must be encoded when used in contexts where they have special meaning
SpaceAlways encoded as %20 (or + in query strings)
%Encoded as %25 - the percent sign itself must be encoded

Common Encoding Examples

Here are real-world examples of URL encoding:

Original:
Hello World
Encoded:
Hello%20World
Original:
café & restaurant
Encoded:
caf%C3%A9%20%26%20restaurant
Original:
price=$100
Encoded:
price%3D%24100

Common URL Encoding Mistakes

Avoid these frequent errors when working with URL encoding:

  • Double encoding: Encoding an already-encoded string results in %2520 instead of %20. Always check if a string is already encoded before encoding again.
  • Encoding entire URLs: Only encode the parts that need encoding (query values, path segments), not the entire URL including protocol and domain.
  • Encoding forward slashes: Forward slashes (/) in paths should NOT be encoded. Only encode them in query parameter values.
  • Encoding query parameters only: Remember that path segments with special characters also need encoding, not just query strings.
  • Case sensitivity: Percent encoding uses uppercase hexadecimal (A-F), though lowercase (a-f) is also valid. Be consistent in your encoding.

encodeURIComponent vs encodeURI

JavaScript provides two encoding functions with different purposes:

encodeURIComponent()

Encodes almost everything, including reserved characters. Use this for encoding query parameter values, form data, or any string that will be part of a URL component.

encodeURI()

Encodes the URI but preserves characters that have meaning in URIs (like :, /, ?, #). Use this when encoding an entire URI that you want to keep functional.

Rule of thumb: Use encodeURIComponent() for values that go INTO a URL (query parameters, path segments). Use encodeURI() only when encoding an entire URL that you want to remain usable.

URL Encoding in Different Languages

Here's how to encode URLs in popular programming languages:

  • JavaScript: encodeURIComponent('hello world') returns 'hello%20world'. For decoding: decodeURIComponent('%20') returns ' '.
  • Python: urllib.parse.quote('hello world') returns 'hello%20world'. For full URLs: urllib.parse.quote_plus() replaces spaces with +.
  • PHP: urlencode('hello world') returns 'hello+world'. Use rawurlencode() for %20 style. htmlspecialchars() is for HTML, not URLs.
  • Java: URLEncoder.encode('hello world', 'UTF-8') returns 'hello+world'. Note: This encodes for forms (application/x-www-form-urlencoded).
  • C#: Uri.EscapeDataString('hello world') returns 'hello%20world'. HttpUtility.UrlEncode() is for form data.

URL Encoding and SEO

URL structure affects search engine optimization:

  • Readable URLs: Search engines prefer clean, readable URLs. Use hyphens instead of encoded spaces when possible: /my-page-title/ is better than /my%20page%20title/.
  • URL slugs: Create SEO-friendly slugs by removing special characters and using lowercase letters. Our Slug Generator tool can help.
  • Query parameters: Encoded parameters are fine for tracking (like UTM codes), but avoid excessive parameters in important pages.
  • Canonical URLs: If you have both encoded and decoded versions of a URL, use canonical tags to tell search engines which version to index.

Frequently Asked Questions

Do I need to encode URLs for API calls?

Yes, always encode query parameter values when building API URLs. For example, if a search term contains '&' or '=', it would break the URL structure without encoding. Most HTTP libraries do this automatically, but verify when building URLs manually.

Why does my URL have %20 instead of spaces?

%20 is the URL-encoded representation of a space character. Spaces aren't valid in URLs, so they're converted to %20 (the hexadecimal ASCII code for space is 20). Some systems use + instead of %20 in query strings, which is also valid.

How do I encode non-English characters in URLs?

Non-ASCII characters are first converted to UTF-8 bytes, then each byte is percent-encoded. For example, 'café' becomes 'caf%C3%A9' because 'é' is encoded as two UTF-8 bytes (C3 A9). Our tool handles this automatically.

Should I encode the entire URL or just parts of it?

Only encode the parts that need it: query parameter values, path segments with special characters, and fragment identifiers. Never encode the protocol (https://), domain, or structural characters like / ? = &. Encoding the entire URL will break it.

Why is my URL double-encoded (%2520 instead of %20)?

Double encoding happens when you encode an already-encoded string. The % in %20 gets encoded as %25, creating %2520. Always check if a string is already encoded before encoding it. If you see %25 in your URL, you've likely double-encoded.