Overview
An HTML anchor link is a typical hyperlink except that it’s used to either jump to another section on the same page or specific section of another page.
First the “bookmarked” area is created by placing an id attribute in a page element you want to link to.
<h2 id="chapter_6">Chapter 6</h2>
Then, elsewhere on the page, you create a link to that bookmark. This link could appear in several locations on the page if necessary to allow the user quick access to the bookmarked area.
What makes it an anchor link is that the href attribute does not contain a URL to another page, but simply the id of the element you want to link to.
<a href="#chapter_6">Go to Chapter 6</a>
An anchor link can also be used to link to a specific section of another page. A typical link will load the new page at the top. However, If you create a bookmarked area somewhere on that new page, you can then link directly to it from a different page by adding the id just after the URL of the target page.
<a href="/pages/my-book.html#chapter_6">Go to Chapter 6</a>
HTML Notes:
- In our HTML section the term “tag” and “element” are often used interchangeably to refer to both the tag used to create a page element and the element created by the tag (<p> tag = <p> element = paragraph on the page)
- HTML5 is not case sensitive; so <P> is the same as <p>, <H1> is the same as <h1>
- Global attributes can be used with all HTML tags and are therefore not mentioned on every tag page
- To write clean, readable HTML code, it is best to use indentation whereas elements within elements are indented (tabbed or spaces) to create something that looks like a project outline
- The browser will automatically remove any extra spaces and lines in your HTML code when the page is displayed
- Double quotes or single quotes can be used around HTML attribute values, but when the attribute value itself contains one form of quote, it will be necessary to use the other around the attribute
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.