Query String Explained: What Comes After the ? in a URL
Published November 25, 2026 · 7 min read
The query string is the part of a URL after the ?. It passes extra information to the page
as key=value pairs joined by &, such as a search term, a page number or a
filter. In shop.com/search?q=shoes&page=2, the query string tells the page to search for
shoes and show page 2.
See every part of a URL at once: paste it into the free URL Parser.
The parts of a URL
https://shop.example.com:443/products/search?q=red+shoes&size=9&page=2#reviews
| Part | Value | What it does |
|---|---|---|
| Protocol | https | How to connect |
| Host | shop.example.com | Which server |
| Port | 443 | The default for HTTPS, so browsers and parsers usually hide it |
| Path | /products/search | Which page |
| Query string | q=red+shoes&size=9&page=2 | Extra data for the page |
| Fragment | reviews | Jumps to a section, never sent to the server |
How the query string works
?starts the query string. Only the first?counts.=joins a key to its value:size=9.&separates pairs:size=9&page=2.- Order usually doesn't matter:
?page=2&size=9works the same way. - Spaces and special characters must be encoded: a space becomes
+or%20. Learn more in What Does %20 Mean in a URL?
Common query string uses
| Use | Example |
|---|---|
| Search | ?q=laravel+tutorial |
| Pagination | ?page=3&per_page=20 |
| Filters and sorting | ?category=shoes&sort=price_asc |
| Tracking | ?utm_source=newsletter&utm_medium=email (see UTM parameters) |
| Language | ?lang=ur |
| Lists of values | ?tag=php&tag=vue or ?tag[]=php&tag[]=vue |
The last row matters for developers. PHP and Laravel read repeated values as a list only when the key
ends in []; otherwise the last value wins. Most other frameworks keep every value, which
you read with getAll() in JavaScript or getlist() in Flask and Django.
How to read query parameters in code
// JavaScript (browser)
const params = new URLSearchParams(window.location.search);
const page = params.get('page'); // "2"
const tags = params.getAll('tag'); // ["php", "vue"]
// PHP
$page = $_GET['page'] ?? 1;
// Laravel
$page = $request->query('page', 1);
# Flask
page = request.args.get('page', 1, type=int)
# Django
page = request.GET.get('page', 1)
Note that every value arrives as text (Flask's type=int is the exception). Convert numbers
yourself, and always validate them before using them in a database query.
Query strings and security
- Never put passwords or secret tokens in a query string. URLs are saved in browser history, server logs and analytics.
- Validate every value. Users can change anything after the
?. - Watch out when sharing links. Remove session IDs, emails or tokens before you send a URL to someone. The URL Parser lists every parameter on its own row, so it is easy to spot what to remove.
Query strings and SEO
Search engines can treat ?sort=price and ?sort=name as separate pages with the
same content. For filter and sort pages, use a canonical tag pointing to the main page. Keep important
content on clean paths like /blog/query-string-explained, not behind parameters. For
encoding values safely, see
URL Encoding Explained.
Paste any link to see its protocol, host, path, query string and fragment, with every parameter decoded on its own row.
Frequently asked questions
What is a query string in a URL?
The text after the ?, made of key=value pairs separated by &.
What is the difference between a query string and a fragment?
The query string is sent to the server. The fragment, after #, stays in the browser and usually jumps to a section.
Can a URL have two question marks?
Only the first ? starts the query string. A second one inside a value should be encoded as %3F.
How long can a query string be?
There is no fixed rule, but keep full URLs under about 2,000 characters to be safe across browsers and servers.
Related articles
What Does %20 Mean in a URL? Every Common Encoded Character
%20 is a space. A table of common encoded characters, %20 vs +, double encoding (%2520), non-English letters, and how to encode in JavaScript, PHP and Python.
Read More →What Are UTM Parameters? How to Read and Use Them
The 5 UTM tags, how to read a tracking link, naming rules that keep reports clean, and how to shorten long UTM links without losing the data.
Read More →URL Encoding Explained: How to Encode and Decode URLs (With Examples)
What URL (percent) encoding is, which characters need it, encoding a value vs a full URL, a table of common codes, JavaScript and PHP examples, and how to fix double-encoding.
Read More →