HTML Class - Fall 2002HTML LinksHTML uses a hyperlink to link to another document on the Web. The Anchor Tag and the HREF AttributeHTML uses the <a> (anchor) tag to create a link to another document. An anchor can point to any resource on the Web: an HTML page, an image, a sound file, a movie, etc. The syntax of creating an anchor:
The <a> tag is used to create an anchor to link from, the href attribute is used to address the document to link to, and the words between the open and close of the anchor tag will be displayed as a hyperlink. This anchor defines a link to this page: The line above will look like this in a browser: Click here to learn about links! The Target AttributeWith the target attribute, you can define where the linked document will be opened. The line below will open the document in a new browser window: The Anchor Tag and the Name AttributeThe name attribute is used to create a named anchor. When using named anchors we can create links that can jump directly into a specified section on a page, instead of letting the user scroll around to find what he/she is looking for. Syntax of a named anchor: The name attribute is used to create a named anchor. The name of the anchor can be any text you care to use. The line below defines a named anchor: You should notice that a named anchor does not display in a special way. To link to the named anchor you add a # sign and the name of the anchor to the end of the URL, like this: The line above will take the user straight to the text within the anchor <a name="links">... </a> within the file "html_links.htm". A hyperlink to the links section from within the file "html_links.htm" will use this syntax: Basic Notes - Useful TipsAlways add a trailing slash to subfolder references. If you link like this: href="http://www.jeremiahfletcher.com/BACE/HTML", you will generate two HTTP requests to the server, because the server will add a slash to the address and create a new request like this: href="http://www.jeremiahfletcher.com/BACE/HTML/" Named anchors are often used to create "table of contents" at the beginning of a large document. Each chapter within the document is given a named anchor, and links to each of these anchors are put at the top of the document. If a browser cannot find a named anchor that has been specified, it goes to the top of the document. No error occurs. Link Tags
|