Query String Explained: What Comes After the ? in a URL

Query String Explained: What Comes After the ? in a URL

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.

Open the URL Parser

The parts of a URL

https://shop.example.com:443/products/search?q=red+shoes&size=9&page=2#reviews
PartValueWhat it does
ProtocolhttpsHow to connect
Hostshop.example.comWhich server
Port443The default for HTTPS, so browsers and parsers usually hide it
Path/products/searchWhich page
Query stringq=red+shoes&size=9&page=2Extra data for the page
FragmentreviewsJumps to a section, never sent to the server

How the query string works

Common query string uses

UseExample
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

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.

Parse a URL

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

← All guides