|
An anchor tag is a tag that allows you to specify a page or a location within a page
to which you can jump. This connection to web documents from other web documents is called a link.
Like all tags, the anchor tag is created using the < > symbols.
Between these symbols the letter A designates the start of the anchor and the /A designates
the end of the anchor. But unlike the previous tags that we have discussed, this tag does nothing
unless tag attributes are included inside the < > symbols. An tag attribute is a modifier of a tag which allows you to specify particular characteristics for the tag. The anchor tag attributes we will use early in this course are HREF and NAME. Note that all tags and attributes are listed in all capital letters. While HTML is not a case-sensitive language, it is common to use all caps in order to enhance the readability of the HTML code.In order to create a link to another web document, your HTML code must include an anchor tag which has the HREF attribute as shown below. <A HREF="firstPage.html">Jump to firstPage.html</A> Notice that the HREF attribute is listed just after the A tag but before the >. A space is required between a tag and an attribute and between multiple attributes. In the example above, HREF (short for Hypertext Reference) is assigned the value of "firstPage.html". It is important to note that the = symbol is used for a subtly different purpose than how it was used in your algebra class. Instead of a declaration that the left hand side and right hand side expressions are equivalent, the = symbol is used to assign the value listed on the right to the variable on the left. The HREF variable can be assigned any value that indicates a location to which a web document can link. In this case, the link will be made to the web page named firstPage.html. Between the beginning and ending anchor tags is the text Jump to firstPage.html. This text will appear in the web browser as hightlighted text. The highlighting usually occurs as underlined text in a different color than other text as shown in the previous line. If an anchor is created with only the NAME attribute, it is used for marking a location within a web document to which you can link. For example, <A NAME="top">The first line of the web document.</A> marks a location called top that is associated with the text "The first line of the web document". Again, the NAME attribute is assigned the value "top". Now, from any location in the document you can link to that first line of text by creating a link to that anchor as shown below. <A HREF="#top">Back to the Top</A> This anchor would appear in your document as the highlighted text shown below. Click on the text and observe what happens. Back to the Top It is important to note that references to named anchors require the # symbol before the anchor name. This is very useful when specifying a particular anchor with a document other than the one in which the link is created. For example, if you wanted to create a link to the bottom of the intro.html page that your read on the first day of this course, you could create the anchor <A NAME="intro.html#bottom">First Day Assignment</A> Of course, the intro.html page has to have an anchor named "text" in order for the link to work. Click on the link below and see how it works. Click the back button on your browser to return to this page. Sample HTML Text |