[HTML] Absolute href vs relative href

An absolute URL - points to another web site (like href="http://www.example.com/default.htm")

A relative URL - points to a file within a web site (like href="default.htm")

When you have a <a href="./a/1.html">W3Schools</a>-- this is a relative URL, assume we are currently on this page: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_a_href

you can open devtool seeing that:

 

Browser will convert a hrefto a absolute url for sure.

 

Rules:

Relative path: 

Given: https://www.example.com/a/b/c/1.html 
href: ./2.html
Result: https://www.example.com/a/b/c/2.html

Given: https://www.example.com/a/b/c/1.html 
href: ../2.html
Result: https://www.example.com/a/b/2.html

Given: https://www.example.com/a/b/c/1.html 
href: ../../d/2.html
Result: https://www.example.com/a/d/2.html

 

Absolute path:

Given: https://www.example.com/a/b/c/1.html 
href: /js/app-zwan123.js
Result: https://www.example.com/js/app-zwan123.js

 

posted @ 2025-02-06 14:37  Zhentiw  阅读(8)  评论(0)    收藏  举报