HTML linking to other documents Free Web Design Tutorials
Home   HTML CSS JavaScript PHP MySQL Usability Glossary
HTMLBasicsCreating a DocumentHead and Body ElementsFormatting TextCreating ListsEmbedding ImagesURLs ExplainedHTML LinkingLinking to DocumentsCreating TablesForms - BasicsInput and TextareaSelect ListsFramesetsThe Frame ElementNested FramesetsTargeting FramesInline Frames

Home > HTML > Linking to Other Documentsprinter version

HTML - Linking to Other Documents

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.

Example of an Absolute and a Relative URL
<a href="http://www.mywebsite.co.uk/mypage.htm">my page</a>
<a href="mypage.htm">my page</a>


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

<a href="mypage.htm" target="window_name">my page</a>

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.



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.

<a href="mypage.htm"><img src="image.gif border="0"></a>


Image Maps

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.

Previous - HTML URLs explained Previous - URLs Explained     Next - Creating Tables Next - HTML creating tables


Privacy | Terms | Contact | Links | Sitemap | RSS Feeds RSS and JavaScript Feeds
©2009 www.webdesignworkmate.co.uk all rights reserved 
Design and Production by smallbizonline website design © 2000-2009
Valid HTML 4.01! Level Double-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0Valid CSS!
Recommended Reading
bullet proof web design

creating web sites

web redesign