URL Encoding Guide: encodeURIComponent vs encodeURI
To URL-encode text, run it through a percent-encoder that converts unsafe characters into %XX escapes β spaces become %20, ampersands become %26, and so on. The ByteTools URL Encoder does this live in your browser and lets you switch between the two encoding modes that trip up most developers.
Getting URL encoding right is one of those small skills that prevents a whole category of broken links, failed redirects and mysterious API errors. The hard part is not the encoding itself β it is knowing which of two very similar functions to use.
Why URL encoding is necessary
A URL has a strict grammar. Characters like ?, &, =, / and # carry structural meaning, and spaces are not allowed at all. The moment you drop raw user input β a search phrase, an email address, a redirect target β into a URL, any of those characters can break the address or change what it points to. Percent-encoding replaces each risky byte with a % followed by its two-digit hex value, neutralising it while keeping it reversible.
This tool is for developers building query strings, share links, mailto URLs and API requests, and for anyone debugging why a parameter is arriving mangled on the server.
How to URL-encode in your browser
- Paste or type the text or full URL you want to encode.
- Choose a mode: Component (encodeURIComponent) for individual values, or Full URL (encodeURI) for a complete address.
- Read the percent-encoded output as it updates live below the input.
- Click Copy to place the encoded string on your clipboard.
encodeURIComponent vs encodeURI: which to use
This is the crux of URL encoding. The two functions differ only in which characters they leave untouched, but choosing wrong will either break your URL's structure or fail to escape a dangerous value.
| Scenario | Use | Why |
|---|---|---|
| A single query value (?q=...) | encodeURIComponent | Escapes &, =, /, ? inside the value |
| A path segment | encodeURIComponent | Protects slashes within the segment |
| An entire assembled URL | encodeURI | Preserves :, /, ?, & structure |
| A redirect target passed as a value | encodeURIComponent | The whole URL is a value here |
A simple rule of thumb: if you are encoding a piece that goes inside a URL, use Component mode. If you are encoding a URL that is already complete and just needs its spaces and unicode cleaned up, use Full URL mode.
Key features and benefits
- Both modes β encodeURIComponent and encodeURI, clearly labelled.
- Live output β see the encoded result as you type.
- UTF-8 aware β emoji and international characters encode to correct byte sequences.
- One-click copy β grab the result instantly.
- Guidance built in β explains which mode fits your use case.
- 100% client-side β internal links and API keys never leave your machine, even offline.
Try the URL Encoder now β it's free and runs entirely in your browser.
Frequently asked questions
What is the difference between encodeURI and encodeURIComponent?
encodeURIComponent escapes every reserved character, including /, ?, & and =, so it is right for individual values. encodeURI leaves those structural characters intact, so it is only for encoding a complete URL whose structure must survive.
When should I URL-encode text?
Any time user or dynamic data goes into a URL: query values, path segments, redirect targets, mailto links and form submissions. Unencoded special characters can break the URL, alter its meaning or open injection risks.
Why does a space become %20 and not a plus sign?
%20 is the standard percent-encoding for a space in a URL. The + convention only applies inside application/x-www-form-urlencoded form data. encodeURIComponent always produces %20, which is safe in both contexts.
How are emoji and non-English characters encoded?
They are converted to UTF-8 bytes first, then each byte becomes a %XX escape. For example Γ© becomes %C3%A9. Any standards-compliant server decodes these back to the original characters.
Can I reverse URL encoding?
Yes β percent-encoding is fully reversible. Use the URL Decoder to turn %XX sequences back into readable text.
Related free tools
- URL Decoder β convert percent-encoded strings back to text.
- Base64 Encoder β encode text or files to Base64.
- Slug Generator β turn titles into clean, URL-friendly slugs.
- HTML Formatter β tidy and indent messy HTML.
Built by ByteVancer
ByteTools is a free product of ByteVancer, a software and web development studio that builds web apps, SaaS platforms and custom software for businesses. If you have a project in mind, explore ByteVancer's services and reach out to hire the team.
Recommended reading
URL Encoding Best Practices and Common Mistakes
Expert URL encoding tips: pick the right mode, avoid double-encoding, handle spaces and reserved characters, and fix the mistakes that break links.
URL Encoding Use Cases: Real Examples That Matter
Real-world URL encoding examples: search links, redirects, mailto, tracking parameters, and API calls β who needs it and exactly how it works.
XOR Cipher Use Cases: CTFs, Learning, and Puzzles
Real use cases for the XOR cipher, from CTF challenges and teaching bitwise logic to lightweight obfuscation, with concrete worked examples.
XOR Cipher Tips: Keys, Security, and Common Mistakes
Pro tips and common mistakes for the repeating-key XOR cipher: key length, reuse pitfalls, format choices, and when to switch to real encryption.