URL encoding (percent-encoding) means replacing characters that aren’t safe or have special meaning with a % followed by two hex digits. That lets you send spaces, symbols and non-ASCII characters in query strings and paths without breaking the URL structure.
Why encode?
In a URL, characters like &, =, ?, #, / and space have special meaning. If a parameter value contains e.g. a&b, the server might treat a and b as separate parameters. Encoding turns a&b into a%26b so it’s treated as one value. The same applies to spaces (encoded as %20 or + in query strings), accents and Unicode: they must be encoded so the URL is valid and not misread.
Where it’s used
- Query strings:
?name=John%20Doe&search=c%23— values with spaces, &, = or special characters must be encoded. - Path segments: if a segment has spaces or reserved characters, encode it (e.g.
/search/hello%20world). - Forms: with GET, fields are sent in the URL and the browser usually encodes them; with POST and
application/x-www-form-urlencodedthe same encoding is used. - Links and APIs: when building URLs in code (e.g. for a link or request), use the language’s encode function (
encodeURIComponentin JavaScript for parameter values, not the full URL).
How to encode and decode
An online URL encoder/decoder lets you paste a URL or text and get the encoded or decoded version. Use it to debug parameters, build correct links or understand a URL full of %XX. In code, don’t concatenate by hand: use encodeURIComponent() for query values in JavaScript and your language’s URL utilities to avoid bugs and security issues.