URL Encoder

Percent-encode text for a URL. By default the tool encodes a single component, so / becomes %2F. Tick Encode Full URL to keep /, : and ? as they are. Picking the wrong mode is a common way to break a redirect.

Input Text
Encoded Output

1 URL Encoder example

Input Text

1
https://example.com/search?q=hello world&lang=en

Encoded Output (Component)

1
https%3A%2F%2Fexample.com%2Fsearch%3Fq%3Dhello%20world%26lang%3Den

2 What the two modes mean

Whole URL (encodeURI)

Leaves the structural characters alone, so :, /, ?, & and = keep working, and encodes spaces and non-ASCII characters. Use it when you are fixing up a complete address.

Single component (encodeURIComponent)

Use this for any value going into a query parameter. It escapes every reserved character, including / and &. Without that, an ampersand in the value splits it into two parameters.

How to use the URL Encoder tool

  1. Paste the text or parameter value into the left editor, or click Upload File to load it from a .txt file. Click Dummy Data to see a worked example.
  2. The right panel encodes as you type using encodeURIComponent(), so every reserved character including / ? & = becomes a percent sequence.
  3. If you pasted a complete URL, tick "Encode Full URL (preserve ://)" to switch to encodeURI(), which keeps the scheme, slashes, ? and & intact.
  4. Click Copy Result to put the encoded string on the clipboard, or Clear to start again.

How to URL encode a string in JavaScript, PHP and Python

JavaScript / Node.js

const value = "hello world & more/100%";

// Encode a single query value (matches the tool's default)
console.log(encodeURIComponent(value));
// hello%20world%20%26%20more%2F100%25

// Encode a whole URL but keep :, /, ? and & intact
console.log(encodeURI("https://example.com/search?q=hello world&lang=en"));
// https://example.com/search?q=hello%20world&lang=en

// Build a query string safely (spaces become +)
const params = new URLSearchParams({ q: value, lang: "en" });
console.log(params.toString());

encodeURIComponent leaves A-Z a-z 0-9 - _ . ! ~ * ' ( ) unencoded, which is slightly looser than RFC 3986 because ! * ' ( ) are reserved there.

PHP

<?php
$value = "hello world & more/100%";

// RFC 3986 encoding: space becomes %20 (same as encodeURIComponent)
echo rawurlencode($value), PHP_EOL;

// Form encoding: space becomes + (application/x-www-form-urlencoded)
echo urlencode($value), PHP_EOL;

// Build a full query string from an array
echo http_build_query(["q" => $value, "lang" => "en"], "", "&", PHP_QUERY_RFC3986), PHP_EOL;

Use rawurlencode() for path segments and REST-style APIs, and urlencode() only for form bodies.

Python

from urllib.parse import quote, quote_plus, urlencode

value = "hello world & more/100%"

# safe="" so the slash is encoded too, like encodeURIComponent
print(quote(value, safe=""))

# Form style: space becomes +
print(quote_plus(value))

# Build a query string from a dict
print(urlencode({"q": value, "lang": "en"}))

quote() keeps / unencoded by default because it is meant for paths. Pass safe="" for query values.

Common errors and how to fix them

The API returns 400 or 404 after I encoded the whole URL
encodeURIComponent() turned https:// into https%3A%2F%2F, so the server saw one long path segment. Encode each parameter value separately, or tick Encode Full URL (preserve ://) in the tool to use encodeURI().
Spaces show up as + on one side and %20 on the other
Both are valid, but + means a space only in application/x-www-form-urlencoded data. Use %20 in paths and in URLs you build by hand. If a server sends you + in a query string, replace it with a space before decoding.
Value arrives double-encoded, for example %2520 instead of a space
The value was encoded twice, usually once by your code and once by an HTTP client or framework that encodes automatically. Encode exactly once, at the point where the URL is assembled.
URIError: URI malformed when encoding
The string contains a lone surrogate half, which is not valid UTF-16 and cannot be turned into UTF-8 bytes. This usually comes from slicing a string in the middle of an emoji. Cut strings on grapheme boundaries instead, for example with Intl.Segmenter.
Ampersand in a value splits my parameters
An unencoded & starts a new parameter. Encode the value so & becomes %26, and the server treats it as part of the same value.

Good to know

RFC 3986 splits characters into two groups. Unreserved ones (letters, digits, - . _ ~) never need encoding. Reserved ones (: / ? # [ ] @ ! $ & ' ( ) * + , ; =) mean something in certain positions, so they must be percent-encoded whenever they are data instead of structure. Everything else, spaces included, becomes UTF-8 bytes and then %XX.

Use encodeURIComponent() unless you are fixing a complete URL. The two functions differ only in which reserved characters they leave alone. encodeURI() assumes it has a whole URL and keeps the delimiters. encodeURIComponent() assumes it has one value and encodes everything reserved.

Specifications and references

This tool follows the specifications below. Read them when you need the exact normative wording, for example to settle an edge case between two implementations.

Guides and tutorials

Frequently Asked Questions

What does URL encoding do?

It replaces characters that are not allowed in a URL, or that would be read as structure, with a percent sign and two hex digits. For example, a space becomes %20 and an ampersand becomes %26, so the server reads them as data.

Should I encode the whole URL or just a value?

Encode each parameter value on its own. Encoding a full URL with encodeURIComponent also encodes the slashes and question mark that give it structure. If you only need to fix spaces or non-ASCII characters in a complete address, tick Encode Full URL (preserve ://).

Why does a space sometimes become a plus sign?

Form submissions (application/x-www-form-urlencoded) use + for spaces. Everywhere else in a URL, use %20. This tool writes %20.

Are Unicode characters supported?

Yes. Characters outside ASCII are encoded as their UTF-8 bytes, each written as a percent sequence. For example, é becomes %C3%A9.

What is the JavaScript equivalent?

encodeURIComponent() for values and encodeURI() for a full URL. The tool calls encodeURIComponent() by default and encodeURI() when Encode Full URL (preserve ://) is ticked.

Related

The URL decoder reverses it. The URL parser shows which part of an address a value belongs to, and the query string parser lists every parameter at once.

More URL Tools

Browse all url tools

Copied to clipboard!