Why every part matters
A URL, short for Uniform Resource Locator, is the address you type or click. It looks like one string, but it is a compact set of instructions. By the end of this lesson you will be able to take any URL apart, say what each piece is for, and spot why a link is broken. The formal description lives in RFC 3986, and the browser's own parsing rules are written down in the WHATWG URL standard. This lesson explains the ideas in plain words.
Here is a made-up address with every part present:
https://shop.example:8443/books/search?q=web+design&page=2#reviewsThe parts, one by one
Scheme: https. Everything before the first ://. It names the protocol to use. On the web you will mostly see https and http. Other schemes exist, for example mailto: to open a mail app. A different scheme is a different set of rules, so http://example.com and https://example.com are not the same address.
Host: shop.example. The machine's name, or an IP address. DNS turns a name into an address (see DNS: the internet's phone book). A host such as www.shop.example is a different host from shop.example, even if both lead to the same site.
Port: :8443. Optional. Each scheme has a default port (443 for https, 80 for http), and when the default is used the port is normally omitted. IP addresses and ports explains the idea.
Path: /books/search. Which resource on that host you want. It looks like folders, and for a simple static site it often is. But the server decides what a path means, so it may run code instead.
Query: ?q=web+design&page=2. Starts with ?. A list of name=value pairs joined by &. The server (or the page's script) reads these to customise the response. The + in a query is commonly read as a space.
Fragment: #reviews. Starts with #. It points at a spot inside the page, such as an element with a matching id. The browser handles it itself and does not include it in the request to the server.
Check your reading with the real parser
Browsers and Node.js ship a URL parser that follows the WHATWG standard. Here is output from parsing the address above, captured on 2026-11 using Node.js. Your own run gives the same pieces:
protocol "https:"
hostname "shop.example"
port "8443"
pathname "/books/search"
search "?q=web+design&page=2"
hash "#reviews"
origin "https://shop.example:8443"
[ [ 'q', 'web design' ], [ 'page', '2' ] ]You can run it yourself. In a browser console or Node.js, type new URL("https://shop.example:8443/books/search?q=web+design&page=2#reviews") and look at its properties. Note that the parser lists the query pairs for you, and read + as a space.
An origin, which you will meet again in later lessons, is the scheme, host and port together. Browsers use it for security rules, for example to decide which pages may read each other's data.
Percent-encoding: when characters need a disguise
A URL may only contain a limited set of characters, and some characters have jobs: ? starts a query, & separates pairs, # starts a fragment. What if you need those characters as ordinary text, or you need a space or an accented letter? You percent-encode them: write each byte as % followed by two hexadecimal digits.
| You want | Written in a URL |
|---|---|
| a space | %20 |
é |
%C3%A9 (two bytes in UTF-8) |
a literal & inside a value |
%26 |
The same parser showed this on 2026-11: asking for https://example.com/a b?x=é produced https://example.com/a%20b?x=%C3%A9. Try your own text in the URL encoder. Encoding matters most in query values. If a visitor searches for fish & chips, an unencoded & would end the value early and the server would see a different search.
Relative and absolute URLs
Inside a page, a link does not have to repeat everything. /menu means "same scheme and host, path /menu". menu.html means "relative to the current folder". https://other.example/ is absolute. The browser fills in the missing parts from the page's own address, so the same HTML works on your laptop and on the live site.
Case, trailing slashes and tidy addresses
The scheme and host are not case-sensitive. The path often is, depending on the server, so /Menu and /menu can be different pages. A trailing slash (/menu/ versus /menu) may also be treated as a different path. Tidy, consistent URLs are easier to read, share and maintain.
Common mistakes
- Putting a password or secret token in a URL. Addresses end up in browser history, logs and shared links.
- Forgetting to encode a value in a query string, so
&or#inside the value breaks the address. - Expecting the fragment to reach the server. It does not.
- Assuming
www.is optional. It is a separate host unless the site is set up to treat them as the same. - Mixing
httpandhttpslinks inside one site by accident.
Exercise
- Take
https://bakery.example:8080/orders/list?status=open&sort=date#topand label scheme, host, port, path, query pairs and fragment. - Write the query string for a search of
rye & seedsfor the keyq, encoding it correctly. - Is
https://bakery.example/Menuguaranteed to show the same page ashttps://bakery.example/menu? Explain.
Show one possible answer
- Scheme
https, hostbakery.example, port8080, path/orders/list, querystatus=openandsort=date, fragmenttop. ?q=rye%20%26%20seeds(a+for each space also works inside query values).- No. Paths can be case-sensitive, depending on the server. Never assume.
Key points
- A URL is made of named parts, and each part answers a different question for the browser or the server.
- The scheme picks the protocol, the host picks the machine, the port picks the door, and the path picks the resource.
- The query string carries extra named values, and the fragment is used by the browser and is not sent to the server.
- Characters that have special meaning or are not allowed are written as percent codes, such as %20 for a space.