To link to another location on the same page, give the destination an id and link to that fragment with href="#id". Modern HTML does not require an empty <a name="..."> anchor.
<a href="#faq">Jump to FAQs</a>
...
<h2 id="faq">Frequently Asked Questions</h2>
Go to the middle example ยท Go to the end example
This heading is the destination of #middle-demo.
This heading is the destination of #end-demo.
<a href="guide.html#examples">Examples in the guide</a>
If a sticky header covers anchored headings, CSS scroll-margin-top can reserve space when the browser scrolls to the target.
h2 { scroll-margin-top: 5rem; }
Use unique IDs, meaningful link text and headings that describe the destination. Fragment links are useful for tables of contents, FAQs and long reference pages.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| vijay | 03-08-2013 |
| Thank You for this article. Your site is nice and easy to understand for learners like me...! thank you. | |