The Many Faces of the Hyperlink Element

Ah, the <a> element. Our friend, the hyperlink. Few HTML elements are as versatile as the hyperlink. We can jump around a page, back and forth between different pages, open our email clients, and execute scripts, all with one meek little HTML tag. Talk about over-achieving...

Don't believe me? Well then, maybe I should show you some examples!

Navigating a Page

One of the more useful ways to implement a hyperlink is to use it as a method of quickly jumping to different topics within a page. This is accomplished by using what are referred to as "page anchors," or "anchors" for short. Creating anchors is a simple, two-step process:

  • Add the "id" attribute to the HTML element closest to where you want the link to "jump" to.
  • Point the "href" attribute of the link tag to that id, preceded with a # sign.

Like so:

		<title>Sample Page</title>
				<h2>Hyperlink Sample Page</h2>
					<li><a href="#one">Link #1</a></li>
					<li><a href="#two">Link #2</a></li>
					<li><a href="">Contact</a></li>
				<h4 id="one">Anchor #1</h4>
					Sample text here. Blah blah blah.
					Blah blah blah some more...
				<h4 id="two">Anchor #2</h4>
					Look! More sample text!
					Isn't HTML neat? :)

Each of the links in the "navigation bar" would take you to a different section of this page.

The MailTo: Link

The "Contact" link in the example above is what is known as a "mailto" link, which gets its name from the fact that you precede the email address in the "href" attribute with "mailto:". The browser recognizes that the link is an email address and causes whatever email client you have installed on your machine to launch.

Linking to Another Page

There are two ways of linking to another page. If you want to link to another page within your website, you only need to specify the folder and file name of the target document. Linking to an entirely different (external) site requires a canonical, or absolute, URL.


  1. Relative (Local site)
    • images/meatball.png
    • code/samples/hello-world.html
  2. Absolute (External site)

El Fin

I will eventually update this post to include some script links, as well, but for now, I think I've given you a good introduction into how to use the hyperlink tag. Questions? Comments? You know what to do...