Anchor
The <a> tag defines a hyperlink, which is used to link from one page to another. An anchor can be used in three ways:
- To create a link to another document, by using the href attribute : <a href="document.html"></a> [Internal (within site)]
- To create a bookmark inside a document, by using the href attribute : <a href="top"></a> [Internal (within page)]
- To create a bookmark inside a document of another website, by using the href attribute</a> [External (outside site)]
Attributes of Ancher Tag:
- href (link to object)
- id (link from object)
- ref (relationship between objects)
- hreflang - specify language of target document
- media - define media
- target
The most important attribute of the <a> element is the href attribute, which indicates the link’s destination.
By default, hyperlinks will appear as follows in all browsers:
- An unvisited link is underlined and blue
- A visited link is underlined and purple
- An active link is underlined and red
You need customize your own colors for your links, hover links, active links, and visited links.
Tips of Using Anchor Tag:
- A linked page is normally displayed in the current browser window, unless you specify another target
- Attributes cannot be present if the href attribute is not present
- Use CSS to style links
Different Ancher Usage Between HTML 4.01 and HTML5
Named Anchors in HTML5
<a href="#top">Top of page</a>
Linking to a Specific Place in a Document
To Create a Named Anchor:
- In the Document window's Design view, place the insertion point where you want the named anchor
- Do one of the followings
- Choose Insert > Named Anchor
- Press Control+Alt+A (Windows) or Command+Option+A (Macintosh)
- Select the Common tab in the Insert bar and click the Named Anchor button
In the Anchor Name field, type a name for the anchor. For more information, see Setting the Named Anchor option.
The anchor marker appears at the insertion point.
Note: If you do not see the anchor marker, choose View > Visual Aids > Invisible Elements.
To Link to a Named Anchor:
- In the Document window's Design view, select text or an image to create a link from.
- In the Link text box of the Property inspector, type a number sign (#) and the name of the anchor. For example:
- To link to an anchor named "top" in the current document, type #top
- To link to an anchor named "top" in a different document in the same folder, type filename.html#top
- Anchor names are case sensitive. To link to a named anchor using the point-to-file methodOpen the document containing the named anchor you want: Choose View > Visual Aids > Invisible Elements to make the anchor visible if you don't see it.
- In the Document window's Design view, select text or an image you want to link from.
- Do one of the following:
- Click the Point-to-File icon to the right of the Link text box in the Property inspector and drag it to the anchor you want to link to: either an anchor within the same document or an anchor in another open document
- Shift-drag in the Document window from the selected text or image to the anchor you want to link to:
either an anchor within the same document or an anchor in another open document. - In the Anchor Name field, type a name for the anchor. For more information, see Setting the Named Anchor option. The anchor marker appears at the insertion point.
Note: If you do not see the anchor marker, choose:
View > Visual Aids > Invisible Elements.