Module 5: Links and Navigation
Absolute, Relative, and Fragment Links
Choose the right URL form for external sites, local files, and locations inside a page.
An absolute URL includes the scheme and host, such as https://example.com/guides/html/. A relative URL is resolved from the current document’s URL. A root-relative URL begins at the site’s root, such as /about/.
<a href="https://www.w3.org/">W3C</a>
<a href="/contact/">Contact</a>
<a href="../resources.html">Resources</a>
<a href="#forms">Jump to forms</a>
A fragment link points to an element with a matching id:
<h2 id="forms">Forms</h2>
IDs should be unique within a document. If two elements share the same ID, fragment navigation and scripting can become unreliable.
A relative link that works from /learn/html/ may resolve differently from /learn/html/forms/. Root-relative paths are often easier for site-wide navigation, while relative paths can be useful in self-contained folders. Test links from the page where visitors will use them.