jakup

For query values & path parts. Encodes reserved chars (/, ?, &, = …). (encodeURIComponent)

Component mode encodes all reserved characters (best for query values); Full URL mode preserves : / ? # & = (best for whole addresses). Spaces become %20 by default, or + with the form option.

Why URLs need encoding

A URL may only contain letters, digits and a few symbols. Spaces, non-Latin characters and symbols such as & ? = break the address or change its meaning if used directly. URL encoding rewrites those characters as a percent sign followed by hexadecimal digits.

A space becomes %20 and an ampersand becomes %26; a non-Latin character usually becomes several %XX groups under UTF-8. It matters when you share a link containing a search term, put a value into a query string, or a link breaks in a messenger app.

You can also go the other way and turn a percent-heavy address back into readable text — handy when checking which search term brought someone to your site. Values are converted only in your browser and never sent to a server.

Frequently asked questions

Should a space be %20 or a plus sign?

Inside a path or an address, %20 is the standard form. A plus sign only means a space in form submissions. Turning on the form option here rewrites %20 as a plus sign, and decoding with the same option turns a plus sign back into a space. Mixing the two up is why a plus sign inside a search term sometimes becomes a space.

What is the difference between encodeURI and encodeURIComponent?

encodeURI is meant for a whole address, so it leaves separators such as colon, slash, question mark, hash and ampersand untouched. encodeURIComponent is meant for a single value and escapes those too. They match full URL mode and component mode here.

Why does one character become three %XX groups?

Encoding works on bytes, not on characters. Under UTF-8 a Korean or Japanese character takes three bytes, so it produces three groups, while an emoji takes four. Latin letters and digits are one byte each, which is why they stay readable.

Why do I see %2520 in my link?

That is a value which was encoded twice. The percent sign itself becomes %25, so %20 turns into %2520. It usually happens when the code that builds a link processes the same value twice. Decoding it twice brings the original text back.

Why does decoding fail?

A percent sign must be followed by two hexadecimal digits. Text containing a literal percent, such as a discount written as 30%, breaks that rule and cannot be decoded. Replace the bare percent with %25, or convert only the unaffected part. If you are unsure whether a value is encoded at all, encode it first and compare.

Which characters are left as they are?

Letters, digits and a small set of marks including hyphen, underscore, period and tilde count as safe and stay readable. Everything else becomes a percent sign plus hexadecimal. Full URL mode additionally keeps the separators that give an address its structure.