Learn HTML For Beginners

HTML Links

The HTML <a> tag defines a hyperlink. A hyperlink (or link) is a word, group of words, or image that you can click on to jump to another document. The most important attribute of the <a> element is the href attribute, which indicates the link's destination. The element a stands for “Anchor” and href is short for “hypertext reference” which specifies where the link leads to typically an address on the internet or a file name. For Example

  <a href="http://www.brainysolutions.org/">Visit Brainy Solutions</a>

Here is the result of this code:

Attributes of Link (<a>)

<a> has some important attributes that you must need to know.

Target

The target attributes specifies where to open the linked document. Following are the possible values that can be set for target attributes.

_blank It opens the linked document in a new window or tab
_parent It opens the linked document in the parent frame
_self It opens the linked document in the same frame. It is the default option.
_top It opens the linked document in the full body of the window
Name of frame Opens the linked document in a named frame

You can use the target attribute according to the requirement. The example below shows how to use different type of target value.

For getting the proper understanding of the target attribute create a new web page using NotePad or any other HTML editor and write the following HTML code.

  <html>
    <head>
          <title>Link Example</title>
    </head>
    <body>
     
        <div>
            <a href="http://www.brainysolutions.org" target="_blank">
                Click Here to Open in New Window
            </a>
        </div>
        <br />
        <div>
            <a href="http://www.bbc.com" target="myFrame">Open BBC</a> |
            <a href="http://www.cnn.com" target="myFrame">Open CNN</a>
        </div>
        <br />
        <iframe name="myFrame" width="100%" height="100px"></iframe>

    </body>
  </html> 
    

The first link has target="_blank" opens the linked document in the new window or tab. The <iframe name="myFrame" /> is a inline frame that is used to embed another document with in the current HTML document. Other 2 links has target="myFrame" and on the click of those links the linked document opens in the inline frame. You can see the output of the HTML below.

id

The idattribute can be used to create a bookmark inside an HTML document. You can move to those bookmarks inside the page using the Link. Suppose you has large text/content on your web page and you want to create some bookmarks there for easy navigation. Create an anchor with an id attribute inside the document.

<a id=”info”>User Information</a>
<div>
Type Long Content Here...
</div>

Create a link “Go to Information” in the same document and when user will click on that link browser will automatically navigate content to the anchored area.

<a href=“#info”>Go to Information</a>

You can test this example with large contents.

;