Prev

Links & Tag Attributes

Absolute vs. Relative URLs

Absolute URLs

Remember: Absolute URLs include the entire web address of a page and always begin with a protocol, usually HTTP.
In the example in the previous section, the value for the href attribute in the anchor tag was http://amazon.com. This probably looks a lot like most URLs you have seen in that it begins with http, which is the protocol for the URL. A protocol tells the browser how to handle what is at the URL. Most web pages use HTTP, which stands for Hypertext Transfer Protocol. When a URL begins with the protocol, followed by "://", it is an absolute URL, which means the entire address is included.

Relative URLs

There is another way to refer to URLs, a sort of shortcut that is often used when authoring web pages, which is a relative URL. A relative URL means you are telling the browser that:

  1. The file you are referring to is using http and
  2. It is on the same web site as the current page

Try It: View the source for this page and look at the URLs to see if they are relative or absolute.
For example, if you view the source of this page, you'll see most of the URLs are relative; they do not specify that the page is http or the name of the server.

Try It: Create another html file and link one to the other with a relative URL.
Relative URLs can be tricky in that you need to pay attention to where the current page is in relation to the file you are pointing to. If you refer to a file in another directory (like a file folder), you have to make a relative path to that file (where putting ../ means to go up a directory). You don't need to do this for this lesson, but you may want to explore it if you make web sites of your own.

End of Topic

Prev