I started learning html recently, and one thing that really confused me is why do some links have a forward-slash(“/”) before the path and some links don’t?
ie.
<link href="/favicon.png" rel="icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
vs.
<dt><a href="reset/index.html">Reset CSS</a></dt>
Is one a relative path and one an absolute path? and how do href’s work exactly? does it just stick on the path name after the base url?
Yes.
If your browser is currently pointing at
http://foo/bar/baz.htmlthen:<a href="reset/index.html">would link tohttp://foo/bar/reset/index.html.<a href="/reset/index.html">would link tohttp://foo/reset/index.html.If there is a base element in the head of your HTML document then the relative path will be relative to the base. For example the link here will take you to
http://example.com/foobar/reset/index.htmlregardless of where the page is located.