Broken URLs are a daily annoyance — spaces in query params, ampersands in values, Unicode in paths. Percent-encoding (URL encoding) fixes it, but encodeURI vs encodeURIComponent trips up even experienced developers.
What is URL encoding?
URL encoding replaces unsafe characters with % followed by two hex digits. A space becomes %20, & becomes %26, and non-ASCII characters become UTF-8 byte sequences (e.g. é → %C3%A9).
Without encoding, special characters break query parsing, routing, and API clients.
encodeURI vs encodeURIComponent
| Function | Use for | Preserves |
encodeURI | Full URLs | /, :, ?, =, &, # |
encodeURIComponent | Query param values | Nothing except unreserved chars |
Rule of thumb: encode individual parameter values with encodeURIComponent. Use encodeURI only when encoding a mostly-complete URL string.
Example
Base URL: https://api.example.com/search Query param: q=hello world&lang=en
Correct: https://api.example.com/search?q=hello%20world&lang=en Wrong: encodeURI("hello world") on just the value — use encodeURIComponent ```
Encode and decode in your browser
The VyomaStack URL Encoder runs 100% locally:
1. Paste a URL or query string into the input 2. Choose encodeURIComponent or encodeURI mode 3. Click Encode or Decode 4. Copy the result or swap input/output for chained fixes
Nothing is sent to a server.
Common URL encoding bugs
- Double encoding —
%2520instead of%20when you encode already-encoded text - Encoding the whole URL with
encodeURIComponent— breaks://and/ - Plus vs space — HTML forms send spaces as
+;decodeURIComponenthandles both - Unicode in paths — modern browsers encode automatically; APIs may not
When you need a URL encoder
- Debug REST API calls with special characters in filters
- Fix broken redirect links from analytics or email tools
- Decode log lines with percent-encoded request paths
- Build query strings for curl or Postman by hand
URL encoder vs JavaScript one-liner
javascript
encodeURIComponent("hello world"); // "hello%20world"
decodeURIComponent("hello%20world"); // "hello world"The browser tool is faster when you're already debugging JSON, SQL, or JWT in VyomaStack — copy button included, no DevTools console.
Related tools
- Base64 Encoder — different encoding for binary/text payloads
- JSON Formatter — validate API bodies before URL-encoding fields
- QR Code Generator — encode URLs into scannable codes
Try it free
Encode and decode URLs instantly — no account, no server upload.