October 7th, 2003

HTML Lesson of the Day

It's about time you learned how to write a hyperlink in HTML.

First of all, HTML tags are written inside <angled brackets>. Many tags are called containers, and they come in pairs. The first tag says when to start a type of markup, and the second tag says when to end. The end tag always starts with a forward slash ( / ). So, all container tags look like this:

<container>stuff in the container</container>

Okay, also, inside the first container you can define attributes to that tag. Most attributes are defined using the syntax attribute="value". If you were using the container <font>, you could define attributes like size="3", face="times new roman" or color="green". Every tag has its own set of attributes you can set.

The tag that creates a hyperlink is actually called an anchor. But the container itself is named <a>. The URL of the hyperlink (the page or site you are linking to) is defined in the attribute href, which stands for "hyper reference". So, a hyperlink tag almost always looks like this:

<a href="http://mysite.com">Visit my site</a>

Don't forget the http:// when writing a link. This is called an absolute reference. Without it, the browser will assume it's a relative reference, which means it will be looking for a document on the same site you are linking from. Chances are you'll be using absolute references most of the time, unless you are writing your own website.

But href is only one attribute for the <a> tag. There is also name, id, class, style, accesskey, tabindex, title and target, to name a few. The one other attribute I use most often is target, and it is handy for making a link automatically launch a new browser window. You can do this by setting target="_blank". Your hyperlink would then look like this:

<a href="http://mysite.com" target="_blank">Visit my site</a>

Feel free to practice making a link by posting a comment here.

Any questions?