Links

Links are found in nearly all web pages.
Links allow users to click their way from page to page.

HTML links are hyperlinks. You can click on a link and jump to another document. When you move the mouse over a link, the mouse arrow will turn into a little hand.

NOTE: A link does not have to be text. A link can be an image or any other HTML element!
eg:
<a href = “https://www.google.co.in/” > google Link (like this one can insert any link required) </a>

The HTML tag defines a hyperlink.
The most important attribute of the element is the href attribute, which indicates the link’s destination.
The link text is the part that will be visible to the reader.
Clicking on the link text, will send the reader to the specified URL address.
By default, links will appear as follows in all browsers:
An unvisited link is underlined and blue A visited link is underlined and purple An active link is underlined and red
NOTE: Links can of course be styled with CSS, to get another look!

Eg: Below is an example of a link.

See the Pen HTML-<a>Tag by Ankit (@AnkitPathshalaCoding) on CodePen.

Target Attribute

By default, after clicking the link, the linked page will be displayed in the current browser window. To change where the link opens, you must specify another target for the link.

The target attribute specifies where to open the linked document.

The target attribute can have one of the following values:

  • _self – Default. Opens the document in the same window/tab as it was clicked
  • _blank – Opens the document in a new window or tab
  • _parent – Opens the document in the parent frame
  • _top – Opens the document in the full body of the window

Exercise 9.1

Try every attribute in the example below and note down the different ways the browser opens

Exercise 9.2

See the Pen HTML-ImageLink by Ankit (@AnkitPathshalaCoding) on CodePen.

Exercise 9.3

Using what you have learnt, create three links as described in the emulator