URL Encoder

Encode URLs and text strings for safe use in web addresses. Convert special characters, spaces, and non-ASCII characters into percent-encoded format for proper URL construction.

A Quick Look at URL Encoder

A URL encoder converts plain text, special characters, spaces, and non-ASCII characters into a format that can be safely transmitted over the internet. Web addresses follow a strict character set defined by RFC 3986, and any character outside that set must be replaced with a percent sign followed by its hexadecimal code point. This process, known as percent-encoding, ensures that every URL is unambiguous and can be interpreted correctly by browsers, servers, and APIs.

Why URLs Need Encoding

URLs are restricted to a specific set of ASCII characters. Characters such as spaces, angle brackets, curly braces, pipes, backslashes, and most non-English letters have special meaning in URLs or are simply not allowed in raw form. When a URL contains these characters unencoded, browsers may interpret them incorrectly, servers may reject the request, or the URL may break mid-string. For example, a space in a query string will split the URL and confuse parsers unless it is encoded as %20. Encoding every unsafe character ensures the URL is a single, well-formed string from start to finish. If you work with HTML content alongside URLs, our HTML to text converter can strip markup before you encode the resulting plain text.

Percent-Encoding Explained

Percent-encoding replaces each unsafe or reserved character with a % followed by the two-digit hexadecimal representation of the character's UTF-8 byte value. A space becomes %20, a hash becomes %23, and an ampersand becomes %26. For characters outside the ASCII range — such as Chinese, Arabic, or accented Latin characters — the UTF-8 encoding may produce multiple bytes, each of which is percent-encoded individually. For instance, the euro sign encodes to %E2%82%AC. This standardized approach ensures any character in any language can be represented safely in a URL.

Try It in Three Steps

The URL encoder on this page works entirely in your browser with no server calls and no data storage. Results appear the moment you click Encode URL.

How to Encode a URL in Seconds

1

Paste Your URL or Text

Copy a URL, query string, or any text containing characters that need encoding, and paste it into the textarea.

2

Choose an Encoding Type

Select encodeURI to encode a full URL while preserving structural characters, or encodeURIComponent to encode an individual component such as a query parameter value.

3

Click Encode URL

The encoded result appears instantly. Click Copy to copy it to your clipboard, or use the Decode toggle to verify the original value.

encodeURI vs encodeURIComponent

JavaScript provides two built-in encoding functions with different scopes. encodeURI is designed for encoding a complete URL. It leaves the structural characters — :/?#[]@!$&'()*+,;= — untouched because they have a defined role in URL syntax. Use it when you have a full URL and need to make it safe without altering its structure. encodeURIComponent is designed for encoding individual components such as query parameter names or values. It encodes everything except the unreserved characters A-Z a-z 0-9 - _ . ~, which means it will encode the ampersand, equals sign, and slash that encodeURI leaves alone. Use it when you are constructing a URL programmatically and need to embed a value that itself contains URL-special characters.

Where URL Encoder Comes in Handy

URL encoding is required in a wide range of development and content workflows. Whether you are building an API request, sharing a link, or handling user-submitted data, encoding ensures the URL reaches its destination intact. The tool is also valuable when testing endpoints, debugging redirects, or preparing URLs for insertion into HTML attributes or JavaScript strings.

Building API Query Strings

When you append user-supplied values to an API endpoint as query parameters, those values may contain characters that would break the URL or be misinterpreted as delimiters. For example, a search term like coffee & tea must be encoded to coffee%20%26%20tea before it is appended to a URL. Using encodeURIComponent on each parameter value — rather than the full URL — ensures the ampersand is treated as part of the value rather than as a query string separator. This is the correct approach for building API requests in JavaScript, Python, or any other language that constructs URLs manually. For generating structured API code, see our AI API generator.

Handling Special Characters in URLs

URLs frequently need to carry values that contain characters with special meaning in URL syntax: spaces, hashes, question marks, equals signs, and slashes. Without encoding, these characters would terminate or restructure the URL unexpectedly. A hash in a parameter value would be read as a fragment identifier, splitting the URL at that point. A question mark inside a path segment would start an unexpected query string. Encoding converts each of these characters to their %XX equivalent, making the URL unambiguous for both the browser and the server. You can also use our AI regex generator to build patterns that match or validate encoded URL strings.

Creating Safe Redirect Links

Redirect URLs are a common target for encoding errors. When the destination URL is passed as a query parameter — for example, /redirect?next=https://example.com/page?id=5 — the inner URL's question mark and equals sign will confuse the outer URL parser. Encoding the destination URL with encodeURIComponent first produces a safe, unambiguous redirect parameter that the server can decode and process correctly. This pattern is used extensively in OAuth flows, login redirects, and third-party integrations.

Sample Outputs

The following examples show how the encoder transforms common inputs. Each example demonstrates a different scenario where encoding is necessary for correct URL handling.

Example 1 — Encoding Spaces in a URL

Spaces are not permitted in URLs. When a URL contains a space, it must be encoded as %20 (or + in form submissions).

Input: https://example.com/search?q=hello world

encodeURI: https://example.com/search?q=hello%20world

encodeURIComponent: https%3A%2F%2Fexample.com%2Fsearch%3Fq%3Dhello%20world

Example 2 — Encoding Query Parameters

When building a URL that includes a parameter value containing special characters, encodeURIComponent is the correct function to use on the value before appending it.

Input value: coffee & tea

encodeURIComponent: coffee%20%26%20tea

Full URL: https://example.com/search?q=coffee%20%26%20tea

Example 3 — Encoding Non-ASCII Characters

Non-ASCII characters such as accented letters, Chinese characters, or symbols are encoded as their UTF-8 byte sequences in percent-encoded form.

Input: café résumé

encodeURIComponent: caf%C3%A9%20r%C3%A9sum%C3%A9

FAQ

The following questions cover the most common points of confusion around URL encoding, from basic definitions to the difference between encoding methods.

What is URL encoding?

URL encoding, also called percent-encoding, is the process of converting characters that are not allowed in a URL into a safe format. Each unsafe character is replaced with a percent sign followed by its two-digit hexadecimal code. For example, a space becomes %20 and an ampersand becomes %26. This ensures the URL is a valid, unambiguous string that browsers, servers, and APIs can interpret correctly.

What characters need to be encoded?

Characters that need encoding include spaces, curly braces {}, square brackets [], pipe |, backslash \, caret ^, backtick `, and any character with a code point above 127 (non-ASCII). Reserved characters such as #, ?, &, =, /, :, @, !, $, ', (, ), *, +, ,, ;, and ~ must also be encoded when they appear in a context where they are not acting as URL delimiters. The exact set depends on which part of the URL they appear in and which encoding function you use.

What is the difference between encodeURI and encodeURIComponent?

encodeURI is used to encode a complete URL. It leaves all characters that have a defined role in URL structure untouched, including :, /, ?, #, [, ], @, !, $, &, ', (, ), *, +, ,, ;, and =. encodeURIComponent is used to encode an individual URL component such as a query parameter value. It encodes everything except the unreserved characters A-Z, a-z, 0-9, -, _, ., and ~. This means encodeURIComponent will encode the / and ? that encodeURI would leave alone.

How do I decode an encoded URL?

To decode a percent-encoded URL, use the Decode toggle button that appears after encoding in this tool. It reverses the encoding by converting each %XX sequence back to its original character using decodeURIComponent. In JavaScript, you can also call decodeURIComponent() or decodeURI() programmatically. Most server-side frameworks decode query parameters automatically before passing them to your code.

Do spaces become %20 or +?

It depends on the context. In a URL path or when using encodeURI or encodeURIComponent, spaces are encoded as %20. In HTML form submissions with the application/x-www-form-urlencoded content type, spaces are encoded as +. This difference matters when reading form data: a + in a query string submitted by a form should be decoded as a space, while %20 is always a space regardless of context. This tool uses the %20 convention, which is correct for general URL encoding.

Do I need to encode the entire URL?

Generally, no. If you have a well-formed URL and only need to make a specific component safe — such as a query parameter value — encode only that component using encodeURIComponent, then assemble the full URL by concatenation. Encoding the entire URL with encodeURIComponent would also encode the structural characters like :// and / in the domain, which would break the URL. Use encodeURI only if you have a complete URL that may contain spaces or non-ASCII characters in the path or query string but is otherwise structurally correct.

Is URL encoding the same as HTML encoding?

No. URL encoding (percent-encoding) replaces characters with %XX sequences for safe transmission in a URL. HTML encoding (also called HTML entity encoding) replaces characters like <, >, &, and " with HTML entities such as <, >, &, and " to prevent them from being interpreted as HTML markup. The two are used in different contexts and are not interchangeable. A URL embedded in an HTML href attribute may need both: the URL itself percent-encoded, and the whole attribute value HTML-encoded if it contains characters like &. For HTML encoding tasks, our HTML to text converter can help strip and decode HTML entities.

What is encode a url?

Encoding a URL means converting its characters into a percent-encoded format that can be safely transmitted over the internet. The phrase 'encode a URL' typically refers to taking a raw URL or text string and applying encodeURI or encodeURIComponent to replace any characters outside the safe ASCII range with their %XX equivalents. This is a standard step when building links programmatically, passing URLs as query parameters, or sending URLs in API requests.

Related Tools