An absolute URL is a complete web address — protocol, domain, and full path — that works no matter where it's placed. It doesn't depend on the current page's location at all.
Syntax
<a href="https://www.codingnowai.in/cources/data-science.php">Data Science Course</a>
Basic Example
<a href="https://developer.mozilla.org/en-US/docs/Web/HTML">MDN HTML Docs</a>
Browser output: a normal link — but this one works identically no matter which page on which site it's placed on, because it fully specifies where it goes.
How It Works
- An absolute URL includes the protocol (
https://), the domain (www.codingnowai.in), and the full path to the resource. - Because nothing is left implicit, the browser needs no extra context — it doesn't matter which page contains the link.
Important Attributes
| Attribute | Purpose |
|---|---|
href | Holds the full absolute URL string itself — this is a URL format concept, not a special HTML attribute |
Real-World Example
<link rel="canonical" href="https://www.codingnowai.in/notes/html/absolute-url">
Canonical tags, Open Graph image URLs, and any link meant to work when shared or syndicated elsewhere must always use absolute URLs — a relative one would be meaningless outside its original page's context.
Comparison: absolute URL vs relative URL
| Absolute URL | Relative URL | |
|---|---|---|
| Format | https://domain.com/path/page.html | /path/page.html or page.html |
| Depends on current page? | No — always resolves the same way | Yes — resolved relative to the current page's URL |
| Best for | Linking to other domains, canonical tags, social sharing metadata, emails | Linking within your own site |
| Downside | Longer to write; breaks if you hardcode the wrong domain (e.g. staging vs production) | Meaningless if copied outside its original site context |
Full breakdown of relative URLs: relative-url.
Common Mistakes
- Hardcoding an absolute URL (including the domain) for internal, same-site links — this breaks the moment the site moves to a new domain or a local/staging environment
- Forgetting the protocol (
https://) entirely, producing a URL the browser can't correctly resolve
Best Practices
- Use absolute URLs for anything meant to work outside the current page's context: canonical tags, Open Graph tags, RSS feeds, emails
- Use relative URLs for ordinary internal site navigation
Accessibility Considerations
No direct accessibility impact — absolute vs relative is purely about how the URL resolves, not how it's announced or navigated.
SEO Considerations
Canonical tags, hreflang tags, and Open Graph metadata are all expected to use absolute URLs — search engines and social platforms may not resolve relative paths correctly in these contexts, which can cause indexing or sharing-preview issues.
Browser & Modern HTML Notes
No special browser behavior here — absolute URLs simply contain everything needed and require no resolution step.
Mini Practice
- Write an absolute URL linking to a page on a completely different website.
- Identify why a canonical tag using a relative URL would be a mistake.