Being able to link to other web pages or web resources is what gives HTML it's power and allows websites to be broken into manageable sized pages instead of one great long page.
To create a hypertext link to another page or resource, the anchor element is used. It takes the form <a href="resource.htm">, has a closing tag and where "resource.htm" is a URL, or address, that points to an available resource on the same, or another, server.
Absolute and Relative URLs
URLs can be absolute or relative to the document root of the server.
The advantage of using relative URLs is that if you decide to move all your pages to another domain, you don't need to rename all the absolute URLs that link to pages on your own site.
The anchor element supports a number of attributes the most important of which is target that causes the document referenced to be loaded into a specified window or frame. This takes the form
Where "window_name" is a separate browser window, the name of an existing frame in a frameset or one of the four special values listed below.
target="_blank" - This loads the document into a new browser window which is not named.
target="_parent" - This loads the document into the immediate parent of the current document, if it exists, or into the whole window if not.
target="_self" - Loads the document into the current window.
target="_top" - Loads the document into the main browser window.
Some of these values are only useful if you are using frames.
Anchors Within Pages
Anchors within a page allow the user to click a link to jump to a specific part of the same page, which is useful for a long page with many sections.
This involves placing an anchor at the top of the section that you wish the link to jump to and takes the form.
<a name="#this_section">this section</a> or <a name="#this_section"></a>
The link that jumps to the anchor above takes the form.
<a href="#this_section">Go to this section</a>
Since "#this_section" is a relative URL it can be expanded to jump to an anchor in another page. This takes the form.
<a href="another_page.htm#this_section">Go to this section on another page</a>
Using Images as Links
It's straightforward to use images as links by substituting an image element for the link text that normally appears within the link. It takes it's most basic form as ...
<a href="mypage.htm"><img src="image.gif></a>
If you rely solely on the image as a link, without any additional text link, then you should make it obvious that it is a link.
In fact the browser will place a border round the image, in the default link colour, if you omit any border attribute within the image element.
If you wish no border then you should set the border attribute to zero.
An image map defines different areas, of a single image, as links to separate resources. The use of image maps is questionable, with regards to usability and accessibility, and so is not covered here.