Query strings are how a URL hands extra information to a page: what to filter, what to search for, where the visitor came from. The query string begins at the first question mark and runs to a # or to the end of the URL. Take this address:
https://example.com/shirts?color=red&size=m#reviews
https://example.comis the scheme and host./shirtsis the path.color=red&size=mis the query string.reviewsis the fragment.
The server, or the page's JavaScript, reads the query string and changes what it shows: here, red shirts in size M. Don't confuse it with a search query, the words someone types into a search engine, although a site's search box often puts those words into a query string.
How a query string is built
Most query strings are a list of key-value pairs:
- An equals sign joins each key to its value:
color=red. - An ampersand separates the pairs:
color=red&size=m. - Characters with a special meaning, and non-ASCII characters, are percent-encoded. A space becomes
+in form-style query strings, or%20. See URL encoding.
Google asks sites to stick to this = and & pattern. Other separators, like colons and brackets, make it hard for crawlers to tell where one parameter ends. Google Search Central
The part after #, the fragment identifier, is different: browsers keep it for themselves and don't send it to the server.
What sites use query strings for
- Filtering and sorting:
?color=red&sort=price-low. - Site search:
?q=rain+jacket. - Pagination:
?page=3. - Campaign tracking: UTM parameters such as
utm_source,utm_mediumandutm_campaigntell analytics tools where a visit came from. Ad platforms add their own, like Google Ads'gclid. - Sessions: some older systems put a session ID in the URL. Google recommends cookies instead.
How query strings affect SEO
To a search engine, every distinct query string makes a distinct URL. /shirts?color=red&size=m and /shirts?size=m&color=red may show the same products, but they're two URLs. Google also treats URLs as case sensitive. That's where the problems start.
Duplicate URLs
Tracking parameters, sort orders and session IDs create many URLs for the same content. Point a canonical tag on those versions at the clean URL, so links and other signals are combined there. Google's own example is a product page reached through a URL with ?gclid= on the end. See duplicate content for the wider issue.
Keep tracking parameters for links from outside your site, such as emails, ads and social posts. Adding them to your own internal links creates extra URLs for the same pages.
Wasted crawling
Filters that can be combined freely, known as faceted navigation, can produce a near-endless number of URLs. Crawlers then spend time on useless combinations and find your new pages more slowly. If you don't need filtered pages in search results, Google suggests:
- blocking the filter parameters in robots.txt, for example
disallow: /*?*color=, or - moving the filters into the fragment (
/items#color=red), which Google ignores when crawling.
If you do want some filtered pages indexed, keep the parameter order consistent, avoid duplicate filters, and return a 404 status when a combination has no results. Canonical tags and nofollow links help less here. See crawl budget.
Search Console used to have a URL Parameters tool for this. Google retired it in 2022 and says its crawlers now learn how to handle parameters on their own. Google Search Central Blog
Query string or path?
Choose by asking whether the URL stands for a page people would search for:
| The URL shows... | Use | Example |
|---|---|---|
| A distinct page you want found in search | A path | /shirts/red/ |
| The same list filtered, sorted or paged | A query string | /shirts?sort=price-low |
| The same page with tracking added | A query string, with a canonical to the clean URL | /shirts?utm_source=newsletter |
Either way, use as few parameters as you can, and drop the ones that don't change the content. See URL structure for naming advice.
Length limits and privacy
There's no single maximum length for a query string. The HTTP standard recommends that browsers and servers support URLs of at least 8,000 bytes. A server that gets a longer URL than it accepts can answer with a 414 (URI Too Long) error. RFC 9110
Never put passwords or personal data in a query string. URLs end up in browser history, bookmarks, server logs and analytics reports, and they're shared freely. Send sensitive form data with a POST request, which puts it in the request body instead of the URL.