The Ultimate Guide to URL Encoding (Percent-Encoding) & RFC 3986
Uniform Resource Identifiers (URIs) are constrained to a specific set of safe ASCII characters. When you pass arbitrary text, spaces, symbols, or international Unicode strings through URL paths or query string parameters (?key=value), characters outside the unreserved character set must be converted into standard percent-encoded sequences (%HH).
Reserved Characters & Percent-Encoded Replacements
| Character | Description | Percent-Encoded | Usage Context |
|---|---|---|---|
| [Space] | Space character | %20 (or + in query) | General text separation |
| ? | Question mark | %3F | Query delimiter |
| & | Ampersand | %26 | Parameter separator |
| = | Equals sign | %3D | Key-value delimiter |
| / | Forward slash | %2F | Path segment separator |
| # | Hash / Number sign | %23 | Anchor / Fragment identifier |
encodeURI vs encodeURIComponent
In JavaScript and modern web frameworks:
• encodeURI: Encodes a complete URI, preserving structural characters like : / ? # & =.
• encodeURIComponent: Encodes individual query parameter values, replacing structural delimiters (like & = ?) so they don't break parameter boundaries.