🛠️DevTools

JavaScript URL Encoding

Compare encodeURI() and encodeURIComponent() behavior. encodeURIComponent encodes more characters and is used for URL parameters, while encodeURI preserves URL structure.

Ad Space - 728x90 Leaderboard
Type:
Try:
0 chars
0 chars
URL Encoding Reference
→ %20
Space
& → %26
Ampersand
= → %3D
Equals
? → %3F
Question mark
/ → %2F
Forward slash
# → %23
Hash
+ → %2B
Plus
@ → %40
At sign
encodeURI vs encodeURIComponent

encodeURIComponent: Encodes all special characters including /, ?, &, =, #. Use for encoding URL parameter values.

encodeURI: Preserves URL structure characters (/, ?, &, =, #, :). Use for encoding entire URLs while keeping them valid.

encodeURIComponent("a=b&c=d") → "a%3Db%26c%3Dd"
encodeURI("a=b&c=d") → "a=b&c=d" (unchanged)
Ad Space - Native/In-content

Frequently Asked Questions

What's the difference between encodeURI and encodeURIComponent?

encodeURI() preserves characters that are part of URL syntax (://?#), while encodeURIComponent() encodes everything except A-Z a-z 0-9 - _ . ~. Use encodeURIComponent for URL parameter values.

Which should I use in JavaScript?

Use encodeURIComponent() for encoding individual URL parameters. Use encodeURI() only when encoding a complete URL and you want to preserve its structure.

Related Tools

📚 Learn More

Ad Space - 728x90 Leaderboard