Anchors in HTML Code
HTML is the language used to code and create websites that Internet users can view in browsers such as Internet Explorer, Firefox and Chrome. Anchors, represented as "<a>" in a Web page's source code, are used in HTML for two reasons: to create a link to another document with the "href" attribute or to create a bookmark within a document with the "name" attribute.
-
Links
-
Links can lead to articles on any other website. Web developers use anchors in HTML to create links either within a document or to a document outside of the current document. These links can lead to subsectionsof the website, such as the links in the navigation bar of a site. The links can also lead to other websites, articles or photos elsewhere on the Internet. Typically the links have a default color scheme involving colors for visited links, active links and unvisited links.
Named Anchor Tags
-
Named anchor tags work like a clickable table of contents in a book. Named anchor tags or bookmarks do not appear as a hyperlink on your website and are often preferred for that fact. The typical code used for a named anchor tag would look like this:
<a name="example-text">Example Text</a>
The text you input for the anchor name should always be one word or connected by a hyphen or underscore.These anchors are used to lead the user to a specific section of a page.
-
Attributes
-
Using additional attributes can make anchor tags easier to understand. In addition to the name attribute used for bookmarks and the "href" attribute used for links, there are other attributes a developer can use in addition to further identify the anchor tag. The attribute "rel" is used to describe the relationship and must be accompanied by the "href" attribute. The "urn" attribute refers to labeling the anchor with a specified uniform resource number that is specific to the page and anchor.
HTML vs. XHTML
-
XHTML is a current coding language for websites that extends HTML's capabilities. One of the biggest differences in the use of anchor tags in HTML versus XHTML is that the "name" attribute is no longer used and should be replaced with "id" attribute that is relateable to CSS Style Sheets.
-
References
- Photo Credit Scott Olson/Getty Images News/Getty Images Sion Touhig/Getty Images Entertainment/Getty Images Jupiterimages/Creatas/Getty Images Jupiterimages/Polka Dot/Getty Images