1 of 12

�HTML – TEXT LINKS ��

Amity School of Engineering & Technology

2 of 12

� 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.

Amity School of Engineering & Technology

3 of 12

�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>

Amity School of Engineering & Technology

4 of 12

  • <!DOCTYPE html>
  • <html>
  • <head>
  • <title>Hyperlink Example</title>
  • </head>
  • <body>
  • <p>Click following link</p>
  • <a href="http://www.gmail.com" target="_self">INBOX</a>
  • </body>
  • </html>

Amity School of Engineering & Technology

5 of 12

�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:

Amity School of Engineering & Technology

6 of 12

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

  • <!DOCTYPE html>
  • <html>
  • <head>
  • <title>Hyperlink Example</title>
  • <base href="http://mail.google.com/">
  • </head>
  • <body>
  • <p>Click any of the following links</p>
  • <a href="/mail/u/0/?ogbl#inbox" target="_blank">Opens in New</a> |
  • <a href="/mail/u/0/?ogbl#inbox" target="_self">Opens in Self</a> |
  • <a href="/mail/u/0/?ogbl#inbox" target="_parent">Opens in Parent</a> |
  • <a href="/mail/u/0/?ogbl#inbox" target="_top">Opens in Body</a>
  • </body>
  • </html>

Amity School of Engineering & Technology

7 of 12

�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.

Amity School of Engineering & Technology

8 of 12

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.google.com/">
  • </head>
  • <body>
  • <p>Click following link</p>
  • <a href="/" target="_blank">HTML Tutorial</a>
  • </body>
  • </html>

Amity School of Engineering & Technology

9 of 12

�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.

  • First create a link to the place where you want to reach with-in a webpage and name it using <a...> tag as follows:

<a name="top"></a>

  • Second step is to create a hyperlink to link the document and place where you want to reach:

<a href="#top">Go to the Top</a>

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.

Amity School of Engineering & Technology

10 of 12

�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.

  • <!DOCTYPE html>
  • <html>
  • <head>
  • <title>Hyperlink Example</title>
  • <base href="http://www.gamil.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>

Amity School of Engineering & Technology

11 of 12

Amity School of Engineering & Technology

12 of 12

Thanks

Amity School of Engineering & Technology