Every URL follows the same pattern defined in RFC 3986. Knowing the parts makes it much easier to see why a link breaks, which part needs encoding, and what a server actually receives.
The parts, labelled
https://user:pass@www.example.com:8080/docs/guide.html?lang=en&page=2#installParsed with the WHATWG URL class, the same parser browsers use: try it in the URL Parser.
| Part | Value | What it does |
|---|---|---|
| Scheme | https: | How to reach the resource: https, http, ftp, mailto and so on. |
| Username and password | user:pass | Optional credentials. Browsers hide or block them; avoid them in links. |
| Host | www.example.com | The domain name or IP address of the server. |
| Port | 8080 | Optional. Omitted when it is the default: 443 for https, 80 for http. |
| Path | /docs/guide.html | Which resource on the server, as segments separated by /. |
| Query | ?lang=en&page=2 | Optional key=value parameters after ?. |
| Fragment | #install | Optional. A position within the page, used only by the browser. |
The host and port together are the authority, and scheme, host and port together are the origin, here https://www.example.com:8080. Browsers use the origin for security rules such as which pages may read each other's data.
URL, URI and URN
- URI is the general term in RFC 3986 for an identifier with this syntax.
- URL is a URI that tells you where the resource is and how to get it, such as an
httpsaddress. - URN names a resource without locating it, such as
urn:isbn:0451450523.
In web development the terms URL and URI are used interchangeably, and the WHATWG URL Standard that browsers follow uses “URL” throughout.
Which characters each part allows
Each part has its own delimiters, so a character that is harmless in one part breaks another. A / is fine in a query value but splits a path; a ? is fine inside the query but ends a path; a # ends whichever part it appears in. That is why values are encoded per part with a component encoder. See invalid URL characters and the percent-encoding table.