HTML and CSS Reference
In-Depth Information
Anchors and the name Attribute
Early Web pages did not support the use of the id attribute as a way of marking loca-
tions within a document. Instead, they used the <a> tag as an anchor or bookmark using
the name attribute
<a name=” anchor ”> content </a>
where anchor is the name of the anchor that marks the location of the document con-
tent. For example, to add an anchor to an h2 heading, you would enter the fol-
lowing code:
<h2><a name=”A”>A</a></h2>
Marking a location with an anchor does not change your document's appearance in
any way; it merely creates a destination within your document. You use the same syntax
to link to locations marked with an anchor as you would with locations marked with id
attributes. To link to the above anchor, you could use the following code:
<a href=”#A”>A</a>
The use of anchors is a deprecated feature of HTML and is not supported in strict
applications of XHTML. The name attribute is not part of HTML5, but you will still see
anchors used in older code and in code generated by HTML editors and converters.
Creating Links to ids in Other Documents
Gerry knows that the glossary will be one of the most useful parts of his Web site, espe-
cially for novice photographers. However, he's also aware that most people do not read
through glossaries. He would like to create links from the words he uses in his articles to
glossary entries so that readers of his articles can quickly access defi nitions for terms they
don't understand. His articles are not on the same page as his Glossary page, so he'll
have to create a link between those pages and specifi c glossary entries.
To create a link to a specifi c location within a document, mark the hypertext link as
<a href=” reference # id ”> content </a>
where reference is a reference to an HTML or XHTML fi le and id is the id of an ele-
ment marked with the id attribute within that fi le. For example, the HTML code
<a href=”glossary.htm#D”>”D” terms in the Glossary</a>
creates a hypertext link to the D entries in the glossary.htm fi le. Note that this assumes
that the glossary.htm fi le is located in the same folder as the document containing the
hypertext link. If not, you have to include either the absolute or relative path information
along with the fi lename, as described earlier.
Search WWH ::

Custom Search