
What Are Query Parameters? Definition and Examples
Query parameters are the hidden switches that tell a website what content to show—without changing the page you’re on. Every time you see a question mark followed by extra text in the address bar, you’re passing key‑value pairs that shape the response.
Bottom line: Query parameters — key‑value pairs after the “?” · Standard: RFC 3986 (URI) · Typical max length: ~2048 characters · Separator: &
Quick snapshot
- Key–value pairs placed after a
? - Sent to server as part of the URL
- Multiple pairs separated by
&
- Exact maximum length varies by browser and server
- Whether order matters depends on server‑side framework
- Query strings have been present since the earliest CGI scripts
- Use
URLSearchParamsfor safe encoding - Never place sensitive data in query strings
| First defined | 1993 by Tim Berners‑Lee |
|---|---|
| Standard | RFC 3986 — URI |
| Typical max length | ~2048 characters |
| Common separator | & (ampersand) |
| Example URL | https://example.com/page?key1=value1&key2=value2 |
| REST usage | filtering, pagination, sorting |
| Case sensitivity | Keys and values are usually case‑sensitive |
| Encoding | Percent‑encoding (UTF‑8) |
What are query parameters in a URL?
Query parameters (also called URL parameters or query strings) are key‑value pairs appended after a question mark. They allow the client to pass extra data to the server without changing the resource path. The server then uses these values to filter, sort, or customize the response.
How do query parameters work?
- They follow the
?in a URL:?key1=value1. - Multiple pairs are separated by
&. - They are defined by RFC 3986 as part of the URI query component.
- Servers access them via
$_GET(PHP),req.query(Node.js), etc.
“When you call a REST API, you often see something like
?page=2&limit=10to paginate results.” – Moesif
What is a query parameter in REST API?
In REST APIs, query parameters are used to refine or filter the resource being requested. They are optional and appear after the endpoint URL. For example, GET /users?role=admin returns only admin users.
What are query parameters in API?
APIs use query parameters to control pagination (?page=1&limit=20), sorting (?sort=name), and filtering (?category=books). They are distinct from path parameters which identify a specific resource.
How to write a query parameter?
Writing a query parameter is straightforward but requires encoding of special characters.
What is the syntax of a query string?
- Start with
?after the base URL. - Write
key=valuefor the first parameter. - Add
&before each additional pair. - Encode keys and values using percent‑encoding (e.g., space →
%20or+).
Example: ?search=hello%20world&lang=en
How to encode special characters in query parameters?
Reserved characters such as ?, &, =, # must be percent‑encoded. Use URLSearchParams in JavaScript or urllib.parse.urlencode in Python.
How to handle multiple values for the same key?
Some frameworks support repeating keys: ?color=red&color=blue. Others expect array notation: ?color[]=red&color[]=blue. Behavior is server‑dependent.
What is an example of a query parameter?
Real‑world examples show how query parameters control every web interaction.
Common examples from Google Search URLs
Google uses ?q=query+parameters for search. The q parameter contains the entered keywords.
Example in a REST API call
“A typical REST API endpoint like
https://api.example.com/articles?author=kay&limit=10uses query parameters to filter and limit results.” – Moesif
Example of pagination using query parameters
?page=2&limit=10 requests the second page of ten items.
What is the difference between a URL and a query parameter?
The confusion often comes from using “URL” and “query parameter” as if they were alternatives. They are not.
URL parameters vs query parameters
“URL parameter” is a broad term that includes both path parameters and query parameters. “Query parameter” refers specifically to the key‑value pairs after ?.
Path parameters vs query parameters in REST APIs
| Aspect | Query parameter | Path parameter | Fragment |
|---|---|---|---|
| Position | After ? |
Inside the path (e.g., /users/123) |
After # |
| Required? | Optional | Usually required | Never sent to server |
| Common use | Filtering, pagination, sorting | Identifying a specific resource | Scrolling to a section |
The implication: Use path parameters when the value is essential to identify the resource; use query parameters for optional refinements.
When to use query parameters vs path parameters
If the parameter identifies a unique entity (e.g., user ID), use a path parameter. If it refines a collection (e.g., search term, page number), use a query parameter.
How to pass query parameters in URL?
Passing query parameters correctly ensures your request is interpreted as intended.
Passing multiple query parameters
- Start with
?. - Write the first pair:
key1=value1. - Append
&and the next pair:&key2=value2. - Continue for all parameters.
Example: https://example.com/search?q=cats&sort=price_asc&page=2
Using the question mark and ampersand
The question mark signals the start of the query string. The ampersand separates individual parameters.
How to build query strings programmatically (JavaScript, Python)
In JavaScript: new URLSearchParams({key: 'value'}).toString()
In Python: urlencode({'key': 'value'})
The catch: Query strings are visible in browser history, server logs, and referrer headers — never pass passwords or tokens this way.
b12.io, en.wikipedia.org, seozoom.com, nordvpn.com, webopedia.com, rubel.dev, devzery.com, blog.apilayer.com, treblle.com, abstractapi.com, britannica.com
FAQ
Can query parameters have multiple values for the same key?
Yes, many servers support repeating keys (e.g., ?color=red&color=blue). However, handling depends on the framework — some require array notation.
Are query parameters case‑sensitive?
Generally yes, both keys and values are case‑sensitive in most implementations. Always match the expected casing.
What is URL encoding for query parameters?
Percent‑encoding (UTF‑8) replaces special characters with % followed by two hex digits. For example, space becomes %20.
How to handle query parameters in JavaScript?
Use the URLSearchParams API: new URLSearchParams(window.location.search).get('key').
Do query parameters affect SEO?
Yes, they can cause duplicate content issues. Use canonical tags and avoid unnecessary parameters in URLs that are indexed.
How to hide query parameters from the URL?
You cannot truly hide them; they are part of the URL. If confidentiality is required, use POST requests or server‑side sessions.
What is the maximum size of a query string?
No official standard. Browsers and servers impose practical limits, commonly ~2048 characters for the entire URL.