HTML URLs: Absolute and Relative Link Paths
Absolute URLs and origin-relative paths
An absolute URL includes its scheme, such as https, and for ordinary web URLs a host. A path beginning with / is relative to the origin (scheme, host and port), not the current directory. For the examples, assume the document URL is https://example.com/guides/start.html.
<a href="https://example.org/help.html">External help</a><a href="/contact.html">Contact</a>The first destination is on example.org; the second resolves to https://example.com/contact.html. These are illustrative URLs, not supplied pages.
Navigate folders
A path without a leading slash is normally resolved from the directory containing the document. ./ means the current directory and ../ moves up one directory. A query beginning with ? can supply parameters to a destination; it is not part of the file name.
<a href="next.html">Next guide</a><a href="../index.html">Home</a><a href="./search.html?q=html">Search guides</a>From the assumed URL these resolve to /guides/next.html, /index.html and /guides/search.html?q=html on example.com.
Understand the base URL
The base URL normally comes from the document URL. A base element in head can change it for relative URLs throughout the document, including fragment links. Use it only intentionally; a wrong base can break many links at once. This example is a full document.
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>Base example</title> <base href="https://example.com/docs/"> </head> <body> <a href="intro.html">Introduction</a> </body></html>The link resolves to https://example.com/docs/intro.html regardless of the original document directory.
Practice and next steps
Assume your page is at https://example.com/shop/items/index.html. Write paths to shop/help.html and the site root contact.html.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML URLs: Absolute and Relative Link Paths — Knowledge Check
Check the core concepts from this lesson.
From https://example.com/a/b/index.html, where does ../help.html resolve?
Which path starts at the origin root?
What can a base element with href change?
From https://example.com/docs/index.html, where does topic.html resolve?
Which URL specifies a scheme and a host independently of the current page?