Understanding Links
Links are snippets of code that give web browsers directions to get from one page to another on the Web. What makes links powerful is that the distance covered by those directions doesn’t matter. A link can lead to another page on the same site just as easily as it can lead to a page on a web server halfway around the globe.
Behind the scenes, a simple HTML tag called the anchor tag (<a>) makes each and every link work. Links come in three flavors: absolute, document-relative, and root-relative. Link Types in Action shows you examples of each in practice.
Absolute Links
When people want to mail you a letter, they ask for your address. Suppose it’s 123 Main St., Smithville, NY 12001, USA. No matter where in the country your friends are, if they write 123 Main St., Smithville, NY 12001, USA on an envelope and mail it, their letters will get to you. That’s because your address is unique.
Similarly, every web page has a unique address, called a URL (most people pronounce it “you-are-el”), or Uniform Resource Locator. If you open a web browser and type http://www.cafesoylentgreen.com/events/index.html into the address bar, the events page for Cafe Soylent Green opens.
This URL is an absolute link—it’s the complete, unique address for a single page. Absolute links always begin with http://, and an absolute link leads to the same destination page, no matter what website page you put that link on—an absolute link in a web page can call up another page within the same site ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access