HTML A Tag

A HTML <a> tag a link tag. It is the address to a webpage/document on the web. It allows quick and easy jumping between webpages without having to type in long addresses into the address bar.

There are two types of links: Hyperlinks and Anchors. A hyperlink is a link to a different page than the page the user is currently on, while an Anchor is a link to somewhere further down the same page.

Anchors are very good where you may have one long document with an index (Think catalogue index) for example. Clicking on a part of the index will take you down the page to the corresponding part in the document.

Both Hyperlinks and Anchor links use the same tag <a>

A HTML Link

In a nutshell to create a HTML link you simply need to write <a href="url">Click me</a>

The click me part between the two > and < arrows is called the content element. This part is what is displayed to the user.

href is an attribute that basically links to an address.
Example:

<a href=”http://www.web-hosting-site.co.uk” >Goto Spyder Hosting!!</a>

Output:
Goto Spyder Hosting!!

Target attribute

There is another attribute it is called the target attribute. This attribute tells the browser where to open the new link, not telling the browser about where to open the link defaults to the same window you are currently in. This is no good though if you just want someone to open up a help window for example while filling out a form! Imagine going half way through a form, clicking the help button and moving to an entirely different screen, you’d then have to go back to the previous page and re-enter all the data! This isn’t a problem though because the target attribute is there to help you. Simply state target=”_blank” in the tag and your link will open in a shiny (well its shiny if you happen to be using Google’s chrome browser) new window!

Example:

<a href=”http://www.web-hosting-site.co.uk” target=”_blank”>Goto Spyder Hosting in a new window</a>

Output:
Goto Spyder Hosting in a new window

Name Attribute

Ok so this is a slightly strange name to be giving the anchor style attribute but I’m not criticising web standards here, in a nutshell the name attribute is used to be an anchor inside a web page.

Example: (a html link heading above has this)

<a name=”ahtmllinkanchor”>Name attribute</a>

Link to heading anchor:

<a href=”#ahtmllinkanchor”>Jump to the html link anchor</a>

You can even link to anchor tag inside a different document(This points to the same page but just imagine it pointed to a different one):

<a href=”http://www.web-hosting-site.co.uk/html/atag.nds#ahtmllinkanchor”>Jump to the HTML Link section heading section in this page</a>

Output:

Jump to the HTML Link section heading
Jump to the HTML Link section heading section in this page