An anchor, hyperlink or link contains at least one attribute, the most common being a Hypertext Reference (HREF). The HREF contains the address and/or path to another document. The address or Uniform Resource Locator (URL) describes where the linked document is located and the method of retrieving that document. The address can be absolute describing the complete address or relative describing the address of a document on the same website.
An example of an anchor with an absolute address would be:
<a href ="http://www.grassrootsdesign.com/">GrassRootsDesign</a>
An example of an anchor with a relative address would be:
<a href="class/a.html">Sample Document</a>
The text between the open and close anchor is the area that the visitor will click on to activate the link. By default this text is blue and underlined though that can be changed with styles.
Though a full path reference or absolute URL is always more accurate and must be used when moving to another site, a relative link works best if the destination document is located on the same site. To create links within a website:
- Just refer to the filename if it's in the same directory
- Type the directory name then a front slash if its in a sub-directory (subdir/doc.html)
- Precede the filename with two dots and a front slash for a parent directory (../doc.html) and repeat this for each parent (../../doc.html).
An anchor can also point to a specific spot or named target in the document. The spot that the link points to must have a name anchor placed there. The reference link includes a number symbol (#) then the name of the anchor. An example of a link to a named anchor would be:
<a href="#sub">Links to a target on the current page</a>
<a href="http://www.grassrootsdesign.com/index.php#sub">Links to a target on a different document</a>
An example of a named anchor would be:
<a name ="sub">Target</a>
Last update: January 5, 2014