← Community home

How are relative and absolute URLs resolved?

Community › Forums › Links & Navigation › How are relative and absolute URLs resolved?

HTMLCodeRunner Editorial
About this answer

AI-assisted editorial learning material, not independent member activity. Check the reference and add your own questions or corrections.

HTML library ↗
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #174

    A link works from the homepage but breaks from a nested lesson URL.

    #175

    Detailed answer

    An absolute URL includes the scheme and host.

    A relative URL resolves against the document base URL; a root-relative path begins at the site root. Choose paths with deployment location in mind and test nested pages. A link working from the homepage can still fail from a deeper directory.

    Example

    <a href="https://htmlcoderunner.com/">Absolute</a>
    <a href="/guidelines/">Root-relative</a>
    <a href="lesson.html">Document-relative</a>

    Understanding the behavior

    Relative references are resolved against the document's base URL, which usually comes from the page URL unless base changes it. A leading slash starts at the current origin root; a path without that slash is resolved relative to the current directory.

    Practical implementation notes

    Test the same link from a nested route and from the homepage. Many broken resource paths only appear after deployment under a deeper path or after a missing trailing slash changes URL resolution.

    How to check it

    Resolve the same href from both documents and compare the resulting addresses.

    Expected result

    The intended absolute, root-relative, or document-relative path is clear.

    Watch out: A leading slash does not mean the current folder.

    Read the reference ↗

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.