← Community home

How do you link to a section on the page?

Community › Forums › Links & Navigation › How do you link to a section on the page?

HTMLCodeRunner Editorial
About this answer

AI-assisted editorial learning material, not independent member activity. Check the reference and add your own questions or corrections.

HTML library ↗
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #176

    A table of contents needs reliable links after headings are edited.

    #177

    Detailed answer

    Give the destination a unique id and use it as the link fragment.

    Fragments work within the current page or after another page's path. Stable IDs preserve incoming links when headings are edited. A fixed header may need scroll-margin styling so the heading remains visible after navigation.

    Example

    <a href="#forms">Go to forms</a>
    <h2 id="forms">HTML forms</h2>

    Understanding the behavior

    A fragment points to an element with a matching id in the target document. The destination must exist and use a unique identifier. A link to another page can also include a fragment after its path.

    Practical implementation notes

    Test the complete URL directly, not only by clicking from the current page. If a sticky header covers the target heading, use a suitable CSS scroll margin rather than inserting empty anchor elements.

    How to check it

    Follow the fragment and check the destination id, including any fixed-header offset.

    Expected result

    The intended section remains reachable through a stable identifier.

    Watch out: Changing visible heading text does not automatically update its id.

    Read the reference ↗

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.