HTML links and anchors: HTML provides useful ways to link to other documents, URLs, images etc. The most convenient way to link to another page would be to use an anchor e.g.
<a href= “http://studybee.net/html-5-and-html-4-difference-features”> Difference in HTML 5 and HTML 4</a>
In the above code <a href= is the beginning tag while </a> is the ending tag. An anchor requires the following to work:
- <a href=
- “the URL or web address”
- The text to show as link e.g. we have “love poetry” as our anchor
Note: the anchor does not show the URL to the user unless mouse hovers over the anchor text. An example would better illustrate this:
HTML Code for displaying anchor text with URL:
<a href=” http://studybee.net/difference-between-html-4-and-5″/>Difference in HTML 5 and HTML 4</a>
Though the browser does not show the link to the website page yet browsers, generally, tend to change the anchor text color to purple or blue. The anchor text is also marked as underlined. However, a web developer has the convenience of changing the style, color and look of an anchor text either through inline styling or by using CSS i.e. Cascading Style Sheets.
Default rendering and output of anchor text code by browsers:
It is interesting to note that our hyperlink or anchor was actually the URL: http://studybee.net/html-5-and-html-4-difference-features but what our user sees is the anchor text: “Difference in HTML 5 and HTML 4”.
Handling of Anchors in HTML:
We have different options to handle HTML links or anchors i.e. we can make them behave as we desire in any of the following manners:
- Target= “_blank”: This would open the link or hyperlink in a new tab or window.
- If we don’t define ‘target=“_blank”’, the HTML link will open the new page in the same window or tab.
Example HTML code redirect users to a new tab or window when they click the anchor text or link:
<a href=” http://studybee.net/html-layout-basic-tags-with-elements/” target=”_blank”/>HTML Basic Layout</a>
Sample HTML code for opening the new page without change of tab or window:
<a href=” http://studybee.net/history-of-html-4-and-html-5/” target=”_blank”/>History of HTML 5</a>