URL
Uniform Resource Locator
The complete address of a resource on the internet — combining scheme, host, optional port, path, optional query string, and optional fragment into a single string that browsers and HTTP clients use to locate and retrieve content.
Every URL follows the structure scheme://host:port/path?query#fragment. Take https://example.com:443/search?q=dns#results: https is the scheme (protocol); example.com is the host (resolved via DNS to an IP); 443 is the port (omitted when it's the scheme default — 443 for HTTPS, 80 for HTTP); /search is the path (the resource on the server); q=dns is the query string (parameters passed to the server); results is the fragment (processed by the browser to scroll to element id="results", never sent to the server).
URL components
| Component | Example | Purpose | Sent to server |
|---|---|---|---|
| Scheme | https | Protocol to use | Implicit (determines port) |
| Host | example.com | Domain or IP of server | Yes (Host header) |
| Port | 8080 | TCP port (omit for defaults) | Yes (implicit) |
| Path | /search | Resource identifier on server | Yes |
| Query string | ?q=dns&page=2 | Key-value parameters | Yes |
| Fragment | #results | In-page anchor (browser-only) | No |
How a browser processes a URL
When you enter a URL, the browser: (1) parses the URL into components; (2) checks if the scheme is supported (http/https/ftp/etc.); (3) DNS-resolves the hostname to an IP address; (4) opens a TCP connection to the IP on the specified port; (5) if HTTPS, performs a TLS handshake; (6) sends an HTTP request with the path, query string, and Host header; (7) receives the response and renders it, then scrolls to the fragment if present. The fragment is local — it's stripped from the request before sending to the server. This is why server-side analytics can't see anchor link navigation within a page.
Frequently Asked Questions
What is the difference between a URL, URI, and URN?
URI (Uniform Resource Identifier) is the broadest term — any string identifying a resource. URL is a URI that also specifies how to locate it (includes scheme and host). URN is a URI that names a resource persistently without location (e.g., urn:isbn:...). In everyday usage, URL and URI are interchangeable for web addresses.
What is URL encoding and why is it needed?
URLs only support a limited ASCII character set. Special characters (spaces, &, #, non-ASCII) must be percent-encoded: space → %20, ñ → %C3%B1. Characters like & and ? have structural meaning in URLs, so literal occurrences in values must be encoded. Use a URL encoding library when building URLs programmatically.
What is the difference between a URL path and a query string?
Path identifies the resource hierarchically: /users/123. Query string passes parameters after ?: ?role=admin&active=true. Fragment (#section) is browser-only and never sent to the server — it scrolls to the matching page element. REST APIs use paths for resources and query strings for filtering.