encodeURIComponent() URL encoding
Last updated: 2026-09-09
encodeURIComponent() URL encoding
encodeURIComponent encodes URI components — the standard for building query parameters.
| Category | Global Functions |
|---|---|
| ES version | ES1 |
📝 Syntax
encodeURIComponent(str);
⚙️ Parameters
| str | The string to encode. |
|---|
Returns:The encoded string.
Mutates the original:No (returns a new value)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
search%20JavaScript%20tutorial
https://example.com/search?q=JS%20tutorial
💡 Tip encodeURIComponent encodes everything including /, ?, & — ideal for parameter values.
⚠️ Warning encodeURI preserves URL structure characters — for encoding full URLs.
🌐 Browser support
| Browser | |||||
|---|---|---|---|---|---|
| encodeURIComponent() | ✓ v1 | ✓ v12 | ✓ v1 | ✓ v1 | ✓ v1 |
| Supported by all modern browsers | |||||
🏷️ Related Items
💡 Related Cases
More case studies coming soon — check back later.
📚 Related Tutorials
❓ FAQ
QencodeURIComponent vs encodeURI?
AencodeURIComponent encodes everything; encodeURI preserves URL structure.
QHow to decode?
AdecodeURIComponent(encoded).
QIs + encoded?
A+ is not encoded; space becomes %20.