HTML Absolute URLs
Imagine you want to tell a friend how to reach your house. You could say, "Turn left at the corner," but that only works if they already know where they are standing. A far better way is to give the full address: house number, street, city, country. It works for anyone, starting from anywhere in the world.
An absolute URL is exactly that: the full address of a page, image, or file on the web. It carries everything a browser needs to find the resource, with no guessing and no dependence on the page you are currently on.
What You Will Learnβ
- What makes a URL absolute
- Every part of a full web address, and what each one does
- Which schemes you can use, such as
https,mailto, andtel - How special characters, spaces, and international names are written in URLs
- When absolute URLs are the right choice, and when they are not
- Common mistakes, and how to avoid them
The Basicsβ
An absolute URL always starts with a scheme (also called a protocol), followed by :// and the location.
- HTML Code
- Browser Output
<p>
Read the HTML guide on
<a href="https://developer.mozilla.org/en-US/docs/Web/HTML">MDN Web Docs</a>.
</p>
<p>
See the official standard at
<a href="https://html.spec.whatwg.org/">the WHATWG website</a>.
</p>
Read the HTML guide on MDN Web Docs.
See the official standard at the WHATWG website.
The demo links point to # so they stay on this page. In your own file, they would go to the full addresses shown in the code.
Because the address is complete, these links work identically on any page, in any folder, on any website.
Anatomy of an Absolute URLβ
Let us take one long address apart.
https://user@www.example.com:8080/courses/html/index.html?lang=en&level=1#links
βββ¬ββ βββ¬ββββββββββ¬ββββββββββ¬ββββββββββββββ¬ββββββββββββββββββββββ¬ββββββββββ¬ββ
scheme user host port path query fragment
| Part | Example | What it does |
|---|---|---|
| Scheme | https | The rule for how to talk to the resource |
| Authority | www.example.com:8080 | The host (server name) and an optional port |
| Path | /courses/html/index.html | Which page or file on that server |
| Query | ?lang=en&level=1 | Extra information, as name and value pairs |
| Fragment | #links | A spot within the page, handled by the browser |
Most links you write use only three of these: scheme, host, and path.
The username (user@) and port (:8080) are uncommon on public websites. Browsers also hide default ports, which are 443 for https and 80 for http. You can safely ignore them in everyday links.
Common Schemesβ
The scheme tells the browser what kind of resource this is and how to open it.
| Scheme | Example | What happens |
|---|---|---|
https | https://example.com | A secure web page. This is the standard today |
http | http://example.com | An unencrypted web page. Avoid for new links |
mailto | mailto:hello@example.com | Opens the email app |
tel | tel:+911234567890 | Starts a phone call |
sms | sms:+911234567890 | Opens a text message |
ftp | ftp://files.example.com | File transfer. Rare, and many browsers no longer support it |
https encrypts the connection, so nobody can read or change the page on its way to the visitor. Almost every site supports it, and browsers warn visitors about plain http. Link to the https version whenever it exists.
You will meet mailto: and tel: links in detail in their own lessons later in this section.