URL Encoding Explained: How to Safely Encode URLs & Query Parameters (2026)

Published April 2, 2026

Have you ever seen URLs with %20 or %E4%B8%AD in them? That's URL encoding (also called percent encoding). It's essential for safely transmitting data in URLs.

What is URL Encoding?

URLs can only contain a limited set of ASCII characters. When you need to include special characters (spaces, Chinese characters, emojis, etc.) in a URL, they must be percent-encoded.

The format is: % followed by two hexadecimal digits representing the byte value.

Common Encodings

Character Encoded Why
Space%20Spaces not allowed in URLs
中文%E4%B8%AD%E6%96%87Non-ASCII characters
&%26Reserved for query string separator
?%3FReserved for query start
#%23Reserved for fragment
/%2FReserved for path separator
=%3DReserved for key=value

When Do You Need URL Encoding?

encodeURIComponent() vs encodeURI()

// encodeURI — encodes a full URL (keeps :/?# etc.)
encodeURI("https://example.com/path?q=hello world")
→ "https://example.com/path?q=hello%20world"

// encodeURIComponent — encodes a single parameter value
encodeURIComponent("hello world & more")
→ "hello%20world%20%26%20more"

Rule of thumb: Use encodeURIComponent() for query parameter values, encodeURI() for full URLs.

🔗 Encode/Decode URLs Now

Free, instant URL encoding and decoding

Open URL Encoder →