Creating Websites: Links

2:10:00 PM |




Links
Of course, the breakthrough that HTML introduced was the ability to allow page authors to create
links from one document to another by marking up specific text with an element that created a reference
(also called a pointer or a hyperlink) to another page. The element that was created for this
purpose is simply called the <a> element, which stands for the anchor element. Authors would place
anchors in their pages that each linked to some other page, and those pages in turn would provide
their own anchors that pointed at other pages; this was the beginning of hypertextual navigation, or
web surfing.
Like the <cite> element, anchors are typically parts of a sentence. To actually create a link, the anchor
needs to do two things. First, it needs to designate something to be the link itself. This is what the user
ends up being able to click. Second, it needs to specify the destination to which the link points. This is
where the web browser will take the user when the user clicks the link.
The link itself is created just like any other element, by enclosing a word or phrase (or other item)
within the <a> element. The resulting content of the link is referred to as the anchor text. Since the
destination at which the link points is metadata, it is specified in an attribute of the <a> element. This
attribute is called the hyperlink reference and is abbreviated to href for short. You can set the href
attribute to any URL on the Internet or to any local page on the current site. Let’s take the following
sentence as an example:
For more information, visit Wikipedia, the free online encyclopedia.
It would make sense to link part of this sentence to Wikipedia, located online at http://
wikipedia.org/. So, use the <a> element, and set the href attribute to the Wikipedia website:
For more information, visit <a href="http://wikipedia.org/">Wikipedia
</a>, the free online encyclopedia.
From a technical perspective, this is absolutely correct. The element is in the right place, it’s wrapped
around the right word, and the attribute is valid. However, there’s something more you should think
about whenever you create links from one page to another. Forgetting to think about it is one of the
most common mistakes that web developers make. What you need to remember to think about is
how you can link up as much relevant text as possible.
There are several reasons why this is an important thing to do. First, it provides a larger clickable area
for the visitor of the website. Rather than having to hover over a single word, multiple words together
provide more room to click, and that makes it easier to use (see Figure 4-1). Second, it creates more
descriptive anchor text, and that can help a person decide whether that link is really what they want
to visit.

0 comments: