← Guides

Anatomy of a URL: Scheme, Host, Path and Query Parameters

The parts of a URL

https://example.com:8443/blog/post?tag=css&page=2#comments
  • https — scheme, which decides the protocol used to fetch the resource
  • example.com — host; the port 8443 is optional and omitted for default ports
  • /blog/post — path, interpreted by the server
  • tag=css&page=2 — query string: key-value pairs separated by &
  • #comments — fragment, handled by the browser and never sent to the server

Percent-encoding

Characters that are not allowed in a URL are encoded as a percent sign followed by two hex digits. A space becomes %20 in a path or query, though form submissions traditionally encode it as +. A literal plus sign in a value must then be sent as %2B, otherwise the server turns it back into a space. This encoding mismatch is one of the most common sources of broken search links and API calls.

Always encode values with the language’s URL API rather than string concatenation. In JavaScript, new URLSearchParams() handles both encoding and repeated keys correctly.

Repeated parameters

?tag=css&tag=js is valid, but what the server does with it is up to the server: some collect an array, some keep the first value, some the last. Never rely on repeated keys unless the API documents the behaviour. Where order matters, encode the values into one parameter with a documented separator.

Fragments and client-side routing

Everything after # stays in the browser: the server never sees it, so it cannot influence caching or server logs. Single-page applications once used fragments for routing for exactly that reason, though the History API has made real paths the better choice for shareable, indexable links.

Relative versus absolute

A leading / makes a path relative to the site root; without it, the reference is relative to the current directory. That difference is why ../ links break when a page moves. For canonical tags, sitemaps and share cards, always use absolute URLs with the scheme and host.

Trailing slashes

/blog/post and /blog/post/ are technically different URLs. Pick one form, redirect the other, and keep internal links consistent — otherwise analytics splits the page and search engines may treat the pair as duplicates.

The userinfo part everyone forgets

The full syntax allows credentials before the host: https://user:password@example.com/. Browsers still parse it, but they strip it from the address bar and many warn before navigating, because it is a classic phishing trick — the real destination is whatever follows the @. Never put credentials in a URL that will be logged, shared or saved as a bookmark; use an Authorization header instead. When you parse a link, read the userinfo field explicitly rather than assuming the host is the first thing after the scheme.

Which part should hold which meaning

The path identifies a resource; the query modifies how that resource is returned. Putting an identifier in the query — /post?id=42 — works, but it hides the hierarchy from caches and search engines and makes relative links harder. Filters, sorting, pagination and search terms belong in the query; a different resource belongs in the path. The fragment is client-side state only: an anchor, a scroll position, or a route in a single-page app. It is never sent in the HTTP request, so server-side rendering cannot branch on it.

Characters that quietly break links

  • & in HTML must be written &, or the parameter splits in the wrong place.
  • A literal # in a value ends the query and starts a fragment; encode it as %23.
  • Spaces, +, / and ? inside values all need percent-encoding.
  • Non-ASCII domains become punycode in the request, so bücher.example is sent as xn--bcher-kva.example.

Length limits and normalisation

There is no limit in the specification, but there are limits in practice: older browsers capped URLs near 2,000 characters, many servers and CDNs default to 8 KB for the request line and headers, and analytics tools truncate long URLs before they appear in a report. Deeply nested filters or a whole JSON payload in a query string will eventually fail somewhere you cannot see. Send large data in a POST body, and keep GET URLs short enough to survive a proxy, an email client and a chat app. Normalise before comparing, too: a trailing slash, a default port, an uppercase host, a different parameter order and an empty parameter all produce different strings for the same page, and a canonical tag should settle the question.

Break a link down field by field with our URL parser. It shows the decoded path, every query parameter including duplicates, and copies the parsed result as JSON.

Try it yourself: open the URL Parser →