HTML Text Links
HTML Text Links
A webpage can contain various links that take you directly to other pages and even specific parts
of a given page. These links are known as hyperlinks.
Hyperlinks allow visitors to navigate between Web sites by clicking on words, phrases, and images.
Thus you can create hyperlinks using text or images available on a webpage.
Linking Documents
A link is specified using HTML tag <a>. This tag is called anchor tag and anything between the
opening <a> tag and the closing </a> tag becomes part of the link and a user can click that part
to reach to the linked document. Following is the simple syntax to use <a> tag.
Example
Let's try following example which links http://www.tutorialspoint.com at your page:
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
</head>
<body>
<p>Click following link</p>
<a href="http://www.tutorialspoint.com" target="_self">Tutorials Point</a>
</body>
</html>
This will produce following result, where you can click on the link generated Tutorials Point to
reach to the home page of Tutorials Point.
Tutorials Point
Option Description
_top Opens the linked document in the full body of the window.
Example
Try following example to understand basic difference in few options given for target attribute.
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
<base href="http://www.tutorialspoint.com/">
</head>
<body>
<p>Click any of the following links</p>
<a href="/html/index.htm" target="_blank">Opens in New</a> |
<a href="/html/index.htm" target="_self">Opens in Self</a> |
<a href="/html/index.htm" target="_parent">Opens in Parent</a> |
<a href="/html/index.htm" target="_top">Opens in Body</a>
</body>
</html>
This will produce following result, where you can click on different links to understand the
difference between various options given for target attribute.
Example
Following example makes use of <base> tag to specify base URL and later we can use relative
path to all the links instead of giving complete URL for every link.
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
<base href="http://www.tutorialspoint.com/">
</head>
<body>
<p>Click following link</p>
<a href="/html/index.htm" target="_blank">HTML Tutorial</a>
</body>
</html>
This will produce following result, where you can click on the link generated HTML Tutorial to
reach to the HTML tutorial.
HTML Tutorial
First create a link to the place where you want to reach with-in a webpage and name it using
<a...> tag as follows:
<h1>HTML Text Links <a name="top"></a></h1>
Second step is to create a hyperlink to link the document and place where you want to reach:
This will produce following link, where you can click on the link generated Go to the Top to reach
to the top of the HTML Text Link tutorial.
Go to the Top
Example
Save the following in test.htm and open it in any web browser to see how link, alink and vlink
attributes work.
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
<base href="http://www.tutorialspoint.com/">
</head>
<body alink="#54A250" link="#040404" vlink="#F40633">
<p>Click following link</p>
<a href="/html/index.htm" target="_blank" >HTML Tutorial</a>
</body>
</html>
This will produce following result. Just check color of the link before clicking on it, next check its
color when you activate it and when the link has been visited.
HTML Tutorial
Download Links
You can create text link to make your PDF, or DOC or ZIP files downloadable. This is very simple,
you just need to give complete URL of the downloadable file as follows:
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
</head>
<a href="http://www.tutorialspoint.com/page.pdf">Download PDF File</a>
</body>
</html>
This will produce following link and will be used to download a file.
For example, if you want make a FileName file downloadable from a given link then its syntax will
be as follows.
#!/usr/bin/perl
# Open the target file and list down its content as follows
open( FILE, "<FileName" );
while(read(FILE, $buffer, 100)){
print("$buffer");
}
Note: For more detail on PERL CGI programs, go through tutorial PERL and CGI.