Relative URLs

A relative URL provides a pointer to another document relative to the location of the current document. The syntax is based on pathname structures in the Unix operating system, which are discussed in Chapter 4. When pointing to another document within your own site (on the same server), it is common to use relative URLs.

For example, if I am currently in resume.html (identified here by its full pathname):

www.littlechair.com/web/work/resume.html

and I want to put a link on that page to a document named bio.html that is in the same directory:

www.littlechair.com/web/work/bio.html

I could use a relative URL as the href attribute value as follows:

<a href="bio.html">...</a>

Using the same example, to link to the file index.html in a higher-level directory (web), I could use the relative pathname to that file as shown:

<a href="../index.html">

This relative URL is the equivalent to the absolute URL http://www.littlechair.com/web/index.html.

Get Web Design in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.