HTML uses a hyperlink to link to another document on the Web
HTML 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:
<a href="url">Text to be displayed</a> |
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 W3Schools:
<a href="http://www.kbcc.cuny.edu/">Visit KCC!</a> |
The line above will look like this in a browser:
Visit KCC
With 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:
<a href=http://www.kbcc.cuny.edu/ target="_blank">Visit KCC!</a> |
The name attribute is used to create a named anchor. When using named anchors we can create links that can jump directly into a specific section on a page, instead of letting the user scroll around to find what he/she is looking for.
Below is the syntax of a named anchor:
<a name="label">Text to be displayed</a> |
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:
<a name="tips">Useful Tips Section</a> |
You should notice that a named anchor is not displayed in a special way.
To link directly to the "tips" section, add a # sign and the name of the anchor to the end of a URL, like this:
<a href="http://www.kbcc.cuny.edu/html_links.html#tips"> Jump to the Useful Tips Section</a> |
A hyperlink to the Useful Tips Section from WITHIN the file "html_links.html" will look like this:
<a href="#tips">Jump to the Useful Tips Section</a> |
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.
Open a link in a new browser window <p> |
|
|---|---|
Link to a location on the same page <p> <h2>Chapter 1</h2> <h2>Chapter 2</h2> <h2>Chapter 3</h2> <h2><a name="C4">Chapter 4</a></h2> <h2>Chapter 5</h2> <h2>Chapter 6</h2> <h2>Chapter 7</h2> <h2>Chapter 8</h2> <h2>Chapter 9</h2> <h2>Chapter 10</h2> <h2>Chapter 11</h2> <h2>Chapter 12</h2> <h2>Chapter 13</h2> <h2>Chapter 14</h2> <h2>Chapter 15</h2> <h2>Chapter 16</h2> <h2>Chapter 17</h2> |
Chapter 1This chapter explains ba bla bla Chapter 2This chapter explains ba bla bla Chapter 3This chapter explains ba bla bla Chapter 4This chapter explains ba bla bla Chapter 5This chapter explains ba bla bla Chapter 6This chapter explains ba bla bla Chapter 7This chapter explains ba bla bla Chapter 8This chapter explains ba bla bla Chapter 9This chapter explains ba bla bla Chapter 10This chapter explains ba bla bla Chapter 11This chapter explains ba bla bla Chapter 12This chapter explains ba bla bla Chapter 13This chapter explains ba bla bla Chapter 14This chapter explains ba bla bla Chapter 15This chapter explains ba bla bla Chapter 16This chapter explains ba bla bla Chapter 17This chapter explains ba bla bla |
| Break out of a frame This example demonstrates how to break out of a frame, if your site is locked in a frame. <p>Locked in a frame?</p> <a href="http://www.kbcc.cuny.edu/" |
Locked in a frame? Click here! |
Create a mailto link <p> <p> |
This is a mail link: Send Mail Note: Spaces between words should be replaced by %20 to ensure that the browser will display your text properly. |
| Create a mailto link 2 This example demonstrates a more complicated mailto link. <p> <p> |
This is another mailto link: Send mail! Note: Spaces between words should be replaced by %20 to ensure that the browser will display your text properly. ![]() |