Anchor Tags and HTML Links
Through HTML, web developers have the ability to link text and images to another document which is stored on the same server or a remote server. A hypertext link is marked by the browser by using a different color or underlining the specified text.
To create a single hypertext-related in HTML the <a> tag (anchor tag) is used. To include an anchor in your document follow the steps outlined below:
Place an anchor tag, specifying the document that is being linked linking as the href attribute
- Place the data (text/images) that will serve as a link between the opening and closing <a> tags.
- Example <a href="some_page.html">Link to some page</a>
The anchor tag can be used to link documents within the same server by using relative links. Relative links refer to links which specify the location of the current file on the server.
Relative links use the standard UNIX syntax. The parent directory is identified as “.." while the directory separator is “/". For example, to access a file in the parent directory’s misc directory, one would use (../misc/somefile.html).
Alternatively, the anchor tag can be used to specify the absolute pathname (the complete URL) of the file. The World Wide Web uses Uniform Resource Locators (URLs) to specify the location of files on other servers.
It is also possible to use the anchor tag to link to a specific email address on the web by including the mailto attribute in a hyperlink. The format is: <a href="mailto:email@host">Send an email to Someone</a>
Supported linking attributes are:
href - The target URL of the link
name – Used to create a bookmark in a document. In XHTML, the name attribute is replaced by the id attribute.
target – Specifies where to open the target URL.
_blank uses a new window
_self uses the same frame
_parent uses parent frameset
_top uses the full body of the window
Stay tuned for more linking attributes in relation to page sections and images in the next article of the HTML Web Page Coding Series.