Skip to main content

What is a fragment | anchor in a link?

A fragment (anchor) is part of a link that lets you jump not to the whole page, but to a specific spot within it.


How this works

A fragment is marked with the # character followed by the identifier (id) of the element to jump to. When the user clicks such a link, the browser scrolls the page to the needed element.


Example:

html
<a href="#contact">Go to contacts</a> <h2 id="contact">Contacts</h2> <p>Phone, address, email...</p>

When the link is clicked, the page smoothly scrolls to the heading with id="contact".


Fragments can be:

  1. Internal (a link to the same page):
html
<a href="#top">Back to top</a> <div id="top"></div>
  1. External (a link to an anchor on another page):
html
<a href="about.html#team">Our team</a>

This navigates to the about.html page and scrolls to the element with id="team".


Features:

  • An anchor does not need a separate file: it references an element by its id attribute.
  • It is case-insensitive (#Contact and #contact are the same thing).
  • Used for convenient navigation through long pages, menus, tables of contents, FAQs, and so on.

Conclusion:

A fragment (anchor) is an internal marker on the page, created via id, that lets a link with # instantly move the user to the needed spot without reloading the page.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.