What is the difference between absolute and relative URL in HTML?

An absolute URL is the complete address with protocol and domain. A relative URL is the path from the page you are on.

<!-- absolute -->
<a href="https://www.example.com/contact.html">Contact</a>

<!-- relative -->
<a href="contact.html">Contact</a>
<a href="pages/about.html">About</a>
<a href="../index.html">Home</a>
<a href="/images/logo.png">Root relative</a>
  • Use absolute URLs for other websites.
  • Use relative URLs for your own pages, so the site works on any domain, even on your computer.
  • ../ goes one folder up. A path starting with / starts from the root of the site.

See HTML Links.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.