HTML Class: Creating Links to Other Pages
(with updates by editorial staff)
Creating A Hypertext Link
Just how do you create a link to another website? Read this tutorial for beginning web developers, written in an easy-to-understand format so you will be creating links in no time at all!
Today you will learn only one basic technique: How to create a hyperlink to another page. It's a set tag format that's part of the Hyper Text Markup Language (HTML) like any of the others you may have seen. Once you learn the format, you can make as many links as you want to any other page you want.
Now an example: The code below would create a link to the HTMLGoodies home page.
<A HREF="http://www.htmlgoodies.com">Click Here for HTMLGoodies</A>
Here's What's Happening
- A stands for Anchor. It starts the link to another page.
- HREF stands for Hypertext REFerence. That's a nice, short way of saying to the browser, "This is where the link is going to go."
- http://www.htmlgoodies.com is the FULL ADDRESS (URL) of the link. Also noticethat the address has an equal sign in front of it and is enclosed in quotes. Why? Because it's an attribute of the Anchor tag, which is a command inside of a command.
- Where it reads "Click Here for HTMLGoodies" is where you write the text that you want to appear on the page. The text in that space will appear on the page for the viewer to click. So write something that denotes the link.
- /A ends the entire link command.
Here's what will appear on the page using the command above...
Now, without clicking, simply lay your pointer on the underlined words. You'll see the address of the link you created at the bottom of your browser window, down where it usually reads "Document Done".
What To Write For The Link?
There are a couple different schools of thought on this. One suggests that what you write for links should be quite blatant. This includes text like "Click here for this" or "Here's a link to...". The other states that since the hypertext links will be blue (or whatever color they're set to), the links should be just another word in the text set up as a link.
In reality it depends what you're doing. If you're building a menu bar down the side of your page (like those which appear on the left hand side of this page) then the last thing you want is for every single link to say "Click here for HTML Primer 1 - an introduction", simply because your menu would be as wide as your page...
For accessibility reasons you should try to make sure your links make sense out of context--diasbled people navigating your page can jump around hyperlinks using the "tab" key (there should be one on the left of your keyboard too). If they have skipped directly to your hyperlink which says "here" then they won't know what it's about. If they skip to one that says "HTML Primer: Introduction" then they should know whether or not they want to click.
E-Mail Links From Your Page
This is what's known as a mailto:command. It follows the same coding scheme as the hypertext link above. What this format does is place blue wording on the screen that people can click to send you an e-mail.
Here's the pattern:
<A HREF="mailto:email@example.com">Click Here To Write Me</A>
Notice that it's the same format as a link except in this link you write "mailto:" in place of the http://and you place your e-mail address in place of the page address/URL. Yes, you still need the </A> tag at the end. Please notice there is NO SPACE between the colon and the e-mail address.
Here's what you get using the "mailto:" command above:
Go ahead, click on it. I know you're dying to. You'll get an e-mail dialogue box addressed to me. Then you can write if you want. The same thing will work for you. Just place your e-mail address in place of mine following the format above.
However, please be very careful when using this, for two reasons:
- If the person only has a web-based email account, and hasn't configured an email program on their computer (e.g. if you use Hotmail or Gmail instead of Microsoft Outlook) then it will open their email program for the first time and try to walk them through setting it up. This isn't a good idea if they're new to computers...
- There are now little programs called 'bots' which wander round the internet looking for email addresses to send spam (junk emails) to. If you don't want to receive them (and nobody does), then one part of the solution is not publishing your email address on the internet. So think long and hard before you use a mailto! A web-based form that they can fill out is more secure and works just as well. For details on how to do just that, visit this article on using webforms.
And that wraps up Primer #4. Next time we get into the fun part of the Web--using images.