You are here:   HomeHTML LanguageHTML TutorialHTML MARQUEE
by Dinesh Thakur Category: HTML

Anchors elements are used to link multiple HTML documents. It requires only one tag viz., the <A> tag. It occurs only in the body of an HTML document. If an anchor is used to turn text into a hyperlink, the text is usually colored blue and underlined.

 

Syntax

 

<A href =" " > Content </A>

 

If you want to create a hyperlink   which will take the user to a different page href or hypertext reference is mandatory. For without it, the anchor will not function as a hyperlink.

 

Hyperlinks can be of two type:

 

(1) Links to an external document

(2) Links to a specified place within the same document.

 

EXTERNAL DOCUMENT REFERENCES

 

It links the source document to a specific external document.

 

Example

 

< A href = "main.htm"> Home </ A>

 



Here "HOME" becomes a hyperlink and links to another document. "Main.htm" which is present in the current working directory. If the file is not present in the current directory a relative or absolute path can be specified.

By default a hyper link takes a user to the beginning of the new web page. At times it might be necessary to jump to a particular location within the new web page. To enable a jump to a specific location in a web page, Named Anchors can be set up.

 

Named Anchors

 

Named Anchors are used to create links to a specific location within a page Jumping to a particular location on a web page can be summarized in two steps.

 

Step 1 : Mark the location to be jumped to i.e. identify the location in a web page to jump to by giving the location a name.

 

The "Name" attribute of <A> tag does this

 

Syntax

<A Name = "Location-name" >

 

Example:

 

< A Name = "location 1">

 

This identifies to jump at location l

 

Step 2: While jumping to a specific web page and a specific location on the web page, in addition to the name of the web page to be jumped to, the name of the location on the web page to go to is required.

 

A web page will really be contained in an HTML file. Hence the web page to jump to really requires a filename. ·htm, together with the name of the location to jump to in the HTML file. This is done as follows;

 

Syntax

 

<A href = "file_name. Htm # location_name" > </A>

 

Example

 

<A href= "Main.htm # location 1" > Home </ A> Home becomes a hotspot and leads to a location named location 1" in the file "Main.htm".

 

The following lines of code show the use of external links:

 

MAIN DOCUMENT

 

<HTML>

<HEAD><TITLE>EXTERNAL LINKS </TITLE></HEAD>

<BOOY>

<H2><P>Discover More about Dreamweaver 4 </P></H2>

<A HREF="D:\CODE\lNTRO\DLL.HTM#ONE">What's New in Dreamweaver 4 <A><BR><BR>

<A HREF="D:\CODE\OL 1.HTM#TWO">Dreamweaver Web Site </A><BR><BR>

<A HREF="D:\CODE\OL2. HTM#THREE">Dreamweaver Exchange</ A><BR><BR>

<A HREF="D:\CODE\OL3.HTM#FOUR">Release Notes</A><BR><BR> </BODY> </HTML>

 

CODE OF REFERENCED DOCUMENT

 

<HTML>

<HEAD><TITLE> TEXT FIELDS</TITLE></HEAD>

<BODY BGCOLOR="PINK">

<A NAME= "ONE"><H2> New in Dreamweaver 4</H2>

It highlights the exciting new features included in this release. Thanks to people like you, Macromedia Dreamweaver has become the standard solution for professional web development on both the Windows and Macintosh platforms.

 

</BOOY>

</HTML>

 

As you can observe in the code of main document not only the document name (DLL.HTM) but also the name of the location (/fone") to be referenced is mentioned. Also you will notice in the document (DLL.HTM) the heading "New in Dreamweaver 4" is given an identification number "one" respectively. So when one clicks on the highlighted portion say What's New in Dreamweaver 4 in Figure the href attribute links the user to that part of the external page which is defined by <A NAME= "ONE">. Similarly names of external files and their respective location name are specified for headings Dreamweaver Web Site, Dreamweaver Exchange and Release Notes.

 

INTERNAL DOCUMENT REFERENCES

 

Sometimes a jump is required to a different location in the same document. For example at the bottom of a long page you can provide a link to the top by using named anchor. Now the visitor won’t need to scroll the entire page and can jump directly to the top by just using a mouse click.

 

Since the jump has to be targeted to a specific location the same two steps need to be performed as before i.e. identify a location with a name and then jump to that location using the name. The only difference is that the file name. ·htm now will be the current file name.htm

 

Syntax:

 

<A NAME = "location-name/”>

<A href = " # location_name " >………………. </A>

 

The absence of the filename ·htm before the # symbol indicates that a jump is required within the same document.

 

Example

 

<A NAME =” location 1”>

<A href = “#location 1”> Home </ A>

 

Home becomes a hotspot and leads to a location named location1 in the same Document.



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Search Content







Advance Courses



Basic Courses



Advertise with Us