HTML

All Languages C CPP JAVA HTML CSS JAVASCRIPT PYTHON

Text links (anchors) In Html

html - text links (anchors)

The World Wide Web got its spidery name from the plentiful connections (links) that link websites together with the click of a button. What most people don't know is that HTML links are actually HTML anchors constructed using anchor tags (<a>).

HTML Text Link:

<a>I am a text link!</a>

HTML Text Link:

I am a text link!

While the example above appears and feels like a text link when viewed through a web browser, the element is incomplete as it is missing a vital attribute that references another web page called a Hypertext Reference (href).

html - hypertext reference (href)

A Hypertext Reference (href) is an HTML attribute of an anchor (link) tag that requires a valid URL in order to properly direct a user to a different location. In other words, this Hypertext Reference is where users will navigate to if they do click on this link. Use the demonstration below as a reference.

HTML Text Link Code:

<a href="http://www.google.com/" target="_blank">google</a>
<br />
<a href="http://www.email.com/" target="_blank">email</a>
<br />
<a href="http://www.yahoo.com/" target="_blank">Yahoo</a>

HTML Text Links:

google
email
Yahoo

The address of a website is called a Uniform Resource Locator (a URL), and it acts like a street address for a website as a user is directed from one site to another. There are different types of URLs, and each has a slightly different look. The examples above link to what are known as Global URLs, since they are external web addresses that do not reside on the Tizag.com domain. Here's a look at the different types of URLs.

HTML Text Link Code:

Global - href="http://www.tutorialsproject.com/" Links to other domains outside your website domain.
Local - href="../internal/mypage2.html"   Links to other pages within your website domain.
Internal - href="#anchorname" Links to anchors embedded in the current web page.
html - link targets

The target attribute defines how each link will open when clicked. Will each one open in a new window, or will each one open in the current browser window? As the web designer, you call the shots as to how a user navigates from page to page, so long as you know how to handle the target attribute.

Link Targets:

TargetDescription
_blank Opens new page in a new browser window
_self Loads the new page in the current window
_parent Loads new page into a parent frame
_top Loads new page into the current browser window, cancelling all frames

The two most important values are the top two, (target="_blank" and target="_self"). The _self value is generally the default. It loads each new page in the current browser window, while _blank opens up a new web browser window with each click of the text link. The code below shows how you would link to ESPN.com, a popular sports website. The target attribute is added to allow the browser to open ESPN in a new window, so that the viewer can have a window that remains opened to our website. Here's the example.

HTML Link Target Code:

<a href="http://www.google.com" target="_blank">google.COM</a>

_blank Target:

google.COM

Links are a big part of the user experience for any website. Always try to keep that in mind when working on a site's navigation. A web page that opens a new web browser window each time a user clicks a link is not the greatest way to entice users to stick around.

html - email links

Creating an email link is simple. If you want people to mail you about your site, a good way to do it is place an email link with a subject line already filled out for them.

HTML Email Link Code:

<a href="mailto:email.com?subject=Feedback" >Email.com</a>

Email Links:

Email.com

In some circumstances, it may be necessary to fill in the body of the email for the user as well.

HTML Email Link Code:

<a href="mailto:email.com?subject=Feedback&body=Sweet site!">
Email.co</a>

Complete Email:

email.com

html - download links

Placing files available for download is done in exactly the same fashion as placing text links. However, things become complicated if we want to place image links for download. The best solution for images is to use a thumbnail links, which we will discuss in the next lesson.

HTML Download Link Code:

<a href="http://www.google.com/pics/htmlT/blanktext.zip">Text Document</a>

Download a Text Document:

Text Document

html - default links; base

Use the <base> tag in the head element to set a default URL for all links on a page to go to. It's always a good idea to set a base tag just in case your links become bugged somewhere down the line. Usually, you should set your base to your home page.

HTML Base Link Code:

<head>
  <base href="http://www.google.com/" />
</head>