URL Encode Special Characters
Percent-encode special characters like &, =, ?, #, /, and spaces so they are safe inside a URL.
Open URL Encoder →Why Special Characters Break URLs
Certain characters are reserved in URLs because they have structural meaning:
? starts the query string, & separates parameters, = assigns values, # marks a fragment, and / separates path segments. If your data contains any of these, putting it into a URL unencoded changes what the URL means. Percent-encoding replaces each reserved character with % plus its two-digit hex code, so the data travels safely as a literal value instead of being interpreted as URL syntax.Common Special Characters and Their Codes
- Space →
%20(or+in form data) - & →
%26, = →%3D, ? →%3F, # →%23 - / →
%2F, : →%3A, @ →%40, + →%2B - Unicode & emoji: encoded as UTF-8 bytes, each byte percent-encoded (e.g.
é→%C3%A9). - Use
encodeURIComponent()— it encodes all of these.encodeURI()leaves reserved characters intact and is wrong for individual values.
// JavaScript
encodeURIComponent("name=John & Co. #1?");
// "name%3DJohn%20%26%20Co.%20%231%3F"
// Unicode
encodeURIComponent("café");
// "caf%C3%A9"
// Python
from urllib.parse import quote
quote("name=John & Co. #1?", safe="")