I've been wondering how do other websites do their navigation links. What most beginners like me do is put the whole link inside the tag
or something like this:
But I've seen a lot of websites lately that does this:
and then the browser address bar display it like this
First I want to know how do you call this method? and what are the advantages of doing this. and lastly, how does it actually work?.
I want to research about it but I don't know what to type on google. I did try a lot of keywords I could think of that relates to this but nothing comes close to what I'm looking for
There's 4 basic link types:
href="". This is a short-hand form of "link to yourself". You'll see it used for in-page anchors, such as
href="#top"and the link.
href="news.html". Clicking on this will try to load a
news.htmlpage in the SAME directory as the page that the link is contained in, so if you're on
http://example.com/foo/bar.html, you'll be trying to load
href="/news.html". This will try to load a
news.htmlpage from the document root of the site. If you're on
http://example.com/foo/bar/html, you'll be trying to load
http://example.com/news.html. The leading
/is what makes this a local absolute instead of a relative path.
href="http://example.com/news.html". A full-blown url, which can point to a completely different site if need be. It CAN be point to the exact same site you're on, but essentially it's a "go over there, no matter where over there is".
The best practice (for me?) is the first one, you need to write all the URL for the most readable code..
The first and the 3rd link are the same if you are on the same domain name..
The 2nd is different, if you are on www.example.com/index.html you'll go to www.example.com/news.html.. But if you are on www.example.com/categoy/index.html you'll be redirected to www.example.com/categoy/news.html and not on root directory.
But I don't understand why you talk about /news/ directory ?
Relative URL's will probably get you some results.
news.htmlwill navigate relative to your current location
/news.htmlwill navigate relative to the root domain name
For example if your current location is
href="news.html"will get you to
href="/news.html"will get you to
See also http://www.w3.org/TR/WD-html40-970917/htmlweb.html#h-5.1.2