Query String Structure & Parsing
URL Encoding Guides
A query string is the part of a URL after ?, used to pass extra information to a page. In https://example.com/search?q=book&page=2, the query string is q=book&page=2.
The rules
A query string is key=value pairs joined by &.
?— marks the start of the query string=— separates a key from its value&— separates multiple pairs#— ends the query string (what follows is the fragment/hash)
When a value contains special characters
If a value contains & or =, it clashes with the separators, so the value must be encoded with encodeURIComponent. A search term of a&b has to be written q=a%26b to keep the parameter intact. A space is shown as %20 or + depending on the encoding, and parsers often turn + back into a space.
Parsing safely
Browsers ship URLSearchParams for handling query strings safely. Reaching for it instead of splitting on & yourself handles encoding, duplicate keys and empty values automatically.
This site's Query Parser tab breaks a pasted URL into components and shows each parameter's raw and decoded value side by side.