首页程序设计url Encode Online

urlencode Online

Convert text, query strings or parameters to percent-encoded format instantly.

About urlencode

What urlencode Actually Does

urlencode turns readable text into something that can survive a trip through a URL. A space becomes %20, an & becomes %26, and a Chinese character turns into a short stack of %E4%BD%A0-style triplets. That is the whole job of urlencode: leave nothing raw that a server could mistake for URL syntax, and nothing the transport layer refuses to carry.

The name comes from PHP's urlencode() function, which shipped in 1997. It follows the old application/x-www-form-urlencoded rules and writes a space as +. Its stricter sibling rawurlencode() follows RFC 3986 and writes %20 instead. Both are still everywhere, which is why the same input can produce two different urlencode results and neither one is wrong.

Every urlencode operation on this page runs inside your browser. Nothing you paste is sent anywhere.

urlencode vs encodeURIComponent

Most JavaScript developers reach for encodeURIComponent() the moment they need to urlencode a value, and that instinct is usually correct. The two are close cousins, but they do not leave the same characters alone.

FunctionLeaves unescapedUse it for
encodeURIComponent()A–Z a–z 0–9 - _ . ! ~ * ' ( )One parameter value
encodeURI()The same, plus : / ? # [ ] @ & = + $ ,A complete URL you already trust

The rule is short. Use encodeURIComponent() to urlencode a single value, and encodeURI() for a full link. If you urlencode an entire URL with encodeURIComponent(), the :// and / separators get shredded and the link dies. If you urlencode a parameter with encodeURI(), an & inside the value slips through and splits your query string in half. Match the function to what you are holding.

When You Need to urlencode

Query string values

Anything sitting to the right of a = is a value. If that value contains a space, an &, a +, a #, a /, or any non-ASCII character, it has to be urlencoded before you glue it into the URL. A raw & looks exactly like the start of the next parameter, so the server reads one value as two.

Form submissions

Browsers urlencode form bodies for you by default when the form uses application/x-www-form-urlencoded, but they write spaces as + rather than %20. When you build that body by hand, you own the urlencode step, and you need to match whatever the receiving endpoint expects.

API signatures and redirect URLs

OAuth callbacks, payment gateway return addresses, signed API calls — this is where urlencode trips people up most. The signature parameter must be urlencoded in a fixed order before hashing, and a redirect URL is itself a parameter, so it must be urlencoded before it goes into the outer query string. Skipping that step is the single most common cause of a signature mismatch.

Characters That Must Be urlencode

Only A–Z, a–z, 0–9 and - _ . ~ pass through untouched. Everything else becomes a percent sign plus two hex digits.

Characterurlencode output
space%20 or +
!%21
#%23
$%24
&%26
+%2B
/%2F
:%3A
=%3D
?%3F
@%40
中文%E4%B8%AD%E6%96%87

Common urlencode Mistakes

Encoding the same string twice

A double urlencode turns %20 into %2520, because the percent sign is itself encoded as %25. When a value arrives at the server looking wrong, check whether something along the chain urlencoded it a second time before you blame the backend.

Treating + and %20 as the same thing

Inside a query string they usually mean the same thing, but in a path segment a + is a literal plus sign. If you are unsure which context you are in, urlencode the space as %20; that form is valid in both places.

Trusting the browser to handle non-ASCII

Modern browsers silently urlencode Chinese text or emoji typed into the address bar, but copied links, log files and older clients do not always follow suit. An explicit urlencode is the only behaviour you can count on everywhere.

urlencode Quick Reference

// urlencode a query value in JavaScript
encodeURIComponent('hello world')   // hello%20world
encodeURIComponent('a&b=c')         // a%26b%3Dc
encodeURIComponent('中文')           // %E4%B8%AD%E6%96%87

// urlencode a full URL
encodeURI('https://a.com/p q')      // https://a.com/p%20q

Paste the same strings into the box above to see the urlencode output side by side, then hit copy and drop it straight into your code.

Frequently Asked Questions About urlencode

Is urlencode the same as percent-encoding?

Yes. urlencode is the everyday name; percent-encoding is the formal name from RFC 3986. Both describe the same mechanism: a % followed by two hexadecimal digits representing one byte.

Does urlencode change my data?

No. urlencode changes only how the text is written inside a URL. Decode the result and you get back exactly the bytes you started with.

Why does my urlencode result contain %25?

Because % encodes to %25. If your output is littered with %25, the string was already urlencoded once and has just been urlencoded again. The fix is to decode it first and urlencode once.

Should I urlencode the whole URL or just the parameters?

Only the parameter values. Encoding a complete URL turns :// and / into %3A%2F%2F and %2F, which breaks it. Use encodeURI() for the full link and urlencode each value on its own.

Is this urlencode tool free and private?

Free, and private by design. The urlencode runs in JavaScript on your own machine — your text never leaves the browser tab.