HTML Text Links logo
HTML Basics
What is HTML
Introduction to HTML
HTML Introduction, What is HTML
What is XHTML
What is Attributes in HTML
HTML Formatting
Bold and Italics in HTML
HTML Heading
HTML Elements
HTML Standard Fonts
HTML Forms
HTML Comments
HTML Table
HTML Input Types
HTML Image Links
HTML Text Links
HTML Colors
HTML Title
HTML Paragraphs
HTML Frames
HTML Anchor
HTML Charset
HTML URL Encoding
HTML Backgrounds
HTML Image
HTML Text Formatting
HTML Tables
HTML Basic
HTML Color Names
HTML Input Attributes
HTML Paragraph
HTML Images
Why use XHTML
HTML global attribute spellcheck
Styling the HTML5 Tags
HTML Computer Code Elements
HTML Layout
HTML Entities
HTML Headings
HTML Symbols
XHTML Tips and Tricks
HTML Form Layouts
HTML Table Vs Div Based Layouts
HTML Drag and Drop
HTML Unordered List | HTML Bulleted List
Discuss XHTML
HTTP Status Codes - List of Standard Server Response Codes
HTML global attribute dir
HTML Attributes
HTML Form Elements
HTML Iframes
500+ HTML Color Names
HTML tables - cell alignment, colours, images
HTML Lists
HTML YouTube Videos
How to create a basic html template
HTML Google Maps
HTML Quick Guide
XHTML Quick Guide
Spinners and Sliders in HTML 5
HTML Blocks
HTML Layouts
MIME Media Types
HTML Reference: Special Characters
HTML Exercises
HTML global attribute lang
Getting Started with Tags in HTML and HTML5
HTML Block and Inline Elements
XHTML Introduction
Working with HTML Head Elements
XHTML Useful Resources
Adding captions to images in HTML
HTML 5 Video and Audio
Execute HTML Online
HTML Overview
HTML Video
XHTML Doctypes
HTML 5 Form Elements
учебное руководств HTML
HTML5 Tables
HTML Multimedia
HTML Audio
HTML global attribute data-*
A simple one column layout with HTML5
HTML global attribute contenteditable
HTML global attribute accesskey
HTML Email Links
HTML Ordered, Unordered, and Definition Lists
HTML Style Sheet
HTML Styles
XHTML Summary
HTML global attribute draggable
HTML Character Encodings
HTML Basics
Previous : HTML Image Links Next : HTML Colors

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.

Note − I recommend you to go through a short tutorial on Understanding URL

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.

<a href = "Document URL" ... attributes-list>Link Text</a>


Let's try following example which links at your page −

Live Demo
<!DOCTYPE html>
      <title>Hyperlink Example</title>
      <p>Click following link</p>
      <a href = "" target =
"_self">Tutorials Point</a>

This will produce the following result, where you can click on the link generated to reach to the home page of Tutorials Point (in this example).

The target Attribute

We have used target attribute in our previous example. This attribute is used to specify the location where linked document is opened. Following are the possible options −

Sr.No Option & Description


Opens the linked document in a new window or tab.



Opens the linked document in the same frame.



Opens the linked document in the parent frame.



Opens the linked document in the full body of the window.



Opens the linked document in a named targetframe.


Try following example to understand basic difference in few options given for target attribute.

Live Demo
<!DOCTYPE html>

      <title>Hyperlink Example</title>
      <base href = "/pics/tut/">
      <p>Click any of the following links</p>
      <a href = "/pics/tut/html/index.htm" target =
"_blank">Opens in New</a> |
      <a href = "/pics/tut/html/index.htm" target =
"_self">Opens in Self</a> |
      <a href = "/pics/tut/html/index.htm" target =
"_parent">Opens in Parent</a> |
      <a href = "/pics/tut/html/index.htm" target = "_top">Opens
in Body</a>


This will produce the following result, where you can click on different links to understand the difference between various options given for target attribute.

Use of Base Path

When you link HTML documents related to the same website, it is not required to give a complete URL for every link. You can get rid of it if you use <base> tag in your HTML document header. This tag is used to give a base path for all the links. So your browser will concatenate given relative path to this base path and will make a complete URL.


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.

Live Demo
<!DOCTYPE html>

      <title>Hyperlink Example</title>
      <base href = "/pics/tut/">
      <p>Click following link</p>
      <a href = "/pics/tut/html/index.htm" target =
"_blank">HTML Tutorial</a>

This will produce the following result, where you can click on the link generated HTML Tutorial to reach to the HTML tutorial.

Now given URL <a href = "/pics/tut/html/index.htm" is being considered as <ahref = "/pics/tut/html/index.htm"

Linking to a Page Section

You can create a link to a particular section of a given webpage by using name attribute. This is a two-step process.

Note − The name attribute deprecated in HTML5. Do not use this attribute. Use id and title attribute instead.

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 −

<a href = "/pics/tut/html/html_text_links.htm#top">Go to the

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 

Setting Link Colors

You can set colors of your links, active links and visited links using link, alink and vlink attributes of <body> tag.


Save the following in test.htm and open it in any web browser to see how link, alink and vlink attributes work.

Live Demo
<!DOCTYPE html>
      <title>Hyperlink Example</title>
      <base href = "/pics/tut/">
   <body alink = "#54A250" link = "#040404" vlink = "#F40633">
      <p>Click following link</p>
      <a href = "/pics/tut/html/index.htm" target = "_blank"
>HTML Tutorial</a>

This will produce the 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.

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 −

Live Demo
<!DOCTYPE html>

      <title>Hyperlink Example</title>
      <a href = "/pics/tut/page.pdf">Download PDF

This will produce following link and will be used to download a file.

File Download Dialog Box

Sometimes it is desired that you want to give an option where a user will click a link and it will pop up a "File Download" box to the user instead of displaying actual content. This is very easy and can be achieved using an HTTP header in your HTTP response.

For example, if you want make a Filename file downloadable from a given link then its syntax will be as follows.


# Additional HTTP Header
print "Content-Type:application/octet-stream; name = "FileName"
print "Content-Disposition:attachment; filename = "FileName"


# Open the target file and list down its content as follows
open( FILE, "<FileName" );

while(read(FILE, $buffer, 100)){

Note − For more detail on PERL CGI programs, go through tutorial PERL and CGI.

Previous : HTML Image Links Next : HTML Colors
© Copyright 2018 W3Hello Publishing Limited. All rights reserved.
Contact us | Sitemap