Relative URLs Explained: Resolving Links Against the Correct Base

Understand root-relative, path-relative, protocol-relative, fragment, and special-scheme links before converting them to absolute URLs.

6/29/2026Reviewed by the extracturl.link team

Not every hyperlink contains a complete address. Web pages commonly use shorter references that depend on the document location. If you extract ../images/map.png without its base URL, the link is incomplete.

The main forms

  • Absolute: https://example.com/docs/start
  • Root-relative: /docs/start
  • Path-relative: start or ../start
  • Protocol-relative: //cdn.example.com/file.js
  • Fragment-only: #installation
  • Query-only: ?view=print

The browser resolves each form against the document URL. With a base of https://example.com/guides/setup/index.html, ../intro resolves under /guides/intro, while /intro resolves at the site root.

The document can declare another base

HTML may contain a base href element. When present, browsers resolve relative links against that address rather than the address bar. An extraction workflow that ignores the base element can produce valid-looking but incorrect URLs.

Fragments are not separate network resources

A fragment such as #examples points to a location or state inside a document. Removing every fragment can be reasonable for a page inventory, but harmful for a citation list where the exact section matters. Decide based on the purpose of the output.

Special schemes need their own category

mailto:, tel:, and sms: links are actions rather than web pages. javascript: links should not be opened or carried into a normal URL list. Separate action links from HTTP and HTTPS links during review.

Safe resolution procedure

  1. Record the source document URL.
  2. Check whether the HTML declares a base URL.
  3. Resolve each reference with the browser URL standard, not string concatenation.
  4. Preserve fragments until the intended use is clear.
  5. Reject unsupported or executable schemes.
  6. Test examples from nested paths before processing the whole list.

Relative links are meaningful only in context. Keeping the source and base alongside the extracted value prevents the most common path errors.

Relative URLs Explained: Resolving Links Against the Correct Base | URL Extractor