You type and click URLs all day, but each one is a precise little structure with named parts, every one of which has a job. Understanding the anatomy of a URL clears up routing, query strings, encoding and a host of small confusions. This guide breaks one down piece by piece.
The parts in order
- Scheme — https:// — the protocol used to fetch the resource.
- Host — example.com — the domain identifying the server.
- Port — :443 — which port to connect to, usually implied by the scheme.
- Path — /blog/article — which resource on the server.
- Query — ?page=2&sort=new — extra parameters as key-value pairs.
- Fragment — #section — a location within the page, never sent to the server.
The query string
The query string, beginning with a question mark, carries parameters as key-value pairs joined by ampersands. Servers and applications read these to filter, paginate or configure a response. Because the values can contain spaces and special characters, they must be percent-encoded so they do not clash with the URL’s own punctuation.
The fragment is special
The fragment, after the hash, is unique: it is never sent to the server. The browser keeps it and uses it to scroll to an element or, in single-page apps, to drive client-side routing. That is why changing only the fragment does not reload the page.
Why encoding matters
Characters like spaces, ampersands and question marks have structural meaning in a URL, so when they appear inside a value they must be encoded — a space becomes %20, for instance. Skipping this is a frequent bug, producing broken links or parameters that get cut off at the first special character.
The takeaway
A URL is not an opaque string but a structured address with a scheme, host, path, query and fragment. Knowing what each part does makes routing, linking and debugging far clearer.