Encode and decode special characters in URLs
URL encoding (percent-encoding) replaces unsafe characters in a URL with a percent sign (%) followed by two hexadecimal digits. For example, a space becomes %20, and an ampersand (&) becomes %26. This ensures URLs are transmitted correctly over the internet.
URLs can only contain certain characters from the ASCII set. Characters like spaces, quotes, angle brackets, and non-ASCII characters must be encoded to be safely included in URLs. Without encoding, these characters could break the URL or be misinterpreted by servers.
Characters that need encoding include: spaces, quotes, angle brackets (<>), curly braces ({}), pipe (|), backslash, caret (^), and all non-ASCII characters. Characters that do NOT need encoding are: A-Z, a-z, 0-9, hyphen (-), underscore (_), period (.), and tilde (~).