URL-Encode Special Characters
URL encoding (percent-encoding) converts characters that are not allowed in URLs into a % followed by their hexadecimal ASCII code. Spaces become %20 (or + in query strings), the ampersand & must be encoded in parameter values, and non-ASCII characters like accented letters and emoji require multi-byte UTF-8 encoding. This collection shows the encoded form of the most commonly mishandled characters. Always encode user-supplied values before appending them to URLs to prevent broken links and injection attacks.
# Space Hello World → Hello%20World # Special characters in query values name=John & Jane → name=John%20%26%20Jane [email protected] → email=user%2Btag%40example.com # Path with slashes /files/my document.pdf → /files/my%20document.pdf # Emoji (UTF-8 multi-byte) Hello 👋 → Hello%20%F0%9F%91%8B # Full URL example https://example.com/search?q=C++ programming&lang=en
FAQ
- What is the difference between %20 and + for spaces?
- %20 is the universal percent-encoding for a space that works in any part of a URL. The + character represents a space only in HTML form query strings (application/x-www-form-urlencoded). Use %20 in path segments.
- Which characters are safe in URLs without encoding?
- Unreserved characters that never need encoding: A-Z, a-z, 0-9, hyphen (-), underscore (_), period (.), and tilde (~). All other characters should be percent-encoded when used as data values.
- How are non-Latin characters encoded in URLs?
- Non-ASCII characters are first encoded as UTF-8 bytes, then each byte is percent-encoded. The emoji 👋 is U+1F44B, encoded as the four UTF-8 bytes F0 9F 91 8B, becoming %F0%9F%91%8B.
Related Examples
Base64 encoding is used in dozens of everyday web contexts including HTTP Basic ...
HTML Entity Encoding ExamplesHTML entity encoding converts characters that have special meaning in HTML into ...
OAuth 2.0 Authorization Code FlowThe OAuth 2.0 authorization code flow is the recommended grant type for web appl...