On this page
- Key Takeaways
- Why a heading edit can break a fragment link
- Review old fragment links after a heading rename
- 1. Find the fragments people already use
- 2. Inspect the destination page
- 3. Test each old link
- Keep an old ID when you rename a heading
- Offer a useful fallback for a removed section
- Common Mistakes
- Best Practices
- Conclusion
Broken anchor links after changing headings are often caused by a mismatch between a link’s fragment and the destination page’s IDs. A heading can look correct to readers while its underlying ID has changed or disappeared.
This guide shows editors how to find old fragments, check the published page, and preserve useful links when a section is renamed or removed.
Key Takeaways
- A link ending in
#setupnormally targets an element withid="setup"on the destination page. - Some publishing systems generate heading IDs from heading text; others use explicit IDs or different rules. Check your system’s behavior rather than assuming it.
- Preserve an important old ID when renaming a heading. If a section is removed, consider keeping a brief target that directs readers to relevant information.
- Review the published or previewed HTML, including duplicate IDs, and test the original links in a browser.
Why a heading edit can break a fragment link
The fragment is the part of a URL after #. For example, #setup points to a target within the destination page. In this HTML, the heading is that target:
<h2 id="setup">Setup</h2>
If an edit changes the heading to “Getting started” and the publishing system also changes its ID to getting-started, an existing link to #setup no longer has that matching ID. The page may still open, but the browser may not jump to the intended section.
The visible heading text and its ID are separate pieces of HTML. Changing the text does not inherently require changing an explicitly assigned ID. However, automatic ID generation varies by publishing system, theme, plugin, and configuration.
This guide could not consult the HTML Living Standard or documentation for your publishing system in this run. Check those sources and your system’s settings before relying on a particular ID-generation rule, and verify the actual rendered page.
Advertisement
Review old fragment links after a heading rename
1. Find the fragments people already use
Before editing, record the current heading’s published URL, including its fragment. Look for links to the section in the article’s table of contents, related articles, documentation, release notes, and other content your team maintains. Search your content repository or CMS for the old fragment, such as #setup.
Your inventory will be incomplete: external websites, bookmarks, emails, and shared messages can contain links you cannot edit. That is a reason to preserve important old targets even after updating links you control.
2. Inspect the destination page
Open a published or preview version of the page and use your browser’s developer tools to inspect the heading. Look for its rendered id attribute, not just the heading text or the source Markdown. A publishing system may transform content between editing and publication.
Check the old fragment against the rendered ID exactly, including capitalization. If a link uses an encoded fragment, compare its decoded characters with the ID. Also check the whole rendered page for another element using the same ID. IDs should be unique; duplicate IDs make a link’s destination ambiguous and can cause it to land on an unintended element.
Pay particular attention when headings have identical or similar text. An automatic generator may assign different IDs to them, and an edit or reorder may change what gets generated. The precise behavior is system-dependent; inspect the rendered IDs and consult the documentation for your publishing setup.
3. Test each old link
Open each recorded URL in a browser against the preview or published page. Confirm that it lands on the intended section, not merely that the page loads. Check links from the table of contents separately: a system might regenerate those links while leaving older inbound links broken.
Also check that the target is visible below any fixed header. If it appears hidden, the target may exist even though the jump looks broken; page styling may need adjustment. Repeat the checks after publication, because previews and production pages can use different templates or cached content.
Keep an old ID when you rename a heading
The simplest option, when your editor permits explicit IDs, is to keep the old ID and change only the visible text:
<h2 id="setup">Getting started</h2>
Existing links to #setup can still reach the renamed heading. Update links you control if there is a good editorial reason, but avoid changing the ID solely to match the new wording.
If a new ID is necessary, a separate element can retain the old target. For example, a page that supports this HTML could use:
<span id="setup"></span>
<h2 id="getting-started">Getting started</h2>
Test both fragments and ensure setup is not used elsewhere on the page. An empty target may need styling or placement adjustments to avoid being obscured by a fixed header. Some editors sanitize HTML or offer their own anchor controls, so use the supported method for your publishing system rather than assuming this markup will survive publication.
Advertisement
Offer a useful fallback for a removed section
If readers may still arrive at a removed section, keep a short replacement at its old ID when practical. Explain what changed and point to a relevant destination. For example:
<h2 id="setup">Setup information has moved</h2>
<p>This section has been replaced. See <a href="#getting-started">Getting started</a>.</p>
<h2 id="getting-started">Getting started</h2>
<p>Follow the current setup instructions for this service.</p>
Replace the example text and destination with guidance that is accurate for your page. Verify that the new target exists and that the old ID remains unique. If there is no direct replacement, say so and link to the nearest useful overview or support information instead of sending readers to an unrelated section.
A server does not receive the fragment as part of the HTTP request, so do not assume a server-side redirect can inspect #setup and choose a section based on it. Test any page redirect and fragment behavior in the actual publishing setup.
Common Mistakes
- Checking only the heading text. The visible words may have changed while the ID stayed the same, or the ID may have changed unexpectedly.
- Checking only for a successful page load. A page can load even when the intended fragment target is absent.
- Creating a duplicate ID as a shortcut. Move or replace the existing target instead; do not leave two elements with the same ID.
- Updating only the table of contents. External links and bookmarks may still use the old fragment.
- Assuming every editor generates IDs the same way. Inspect the rendered page and review your own system’s documentation and configuration.
- Removing a section without a destination. Where the old link matters, provide a short explanation and a relevant next step.
Best Practices
- Treat IDs for frequently linked sections as stable identifiers, separate from editorial heading text.
- Record important fragment URLs before a restructure and include them in the publication checklist.
- Prefer explicit IDs where your system supports them. Check automatically generated IDs after renames, duplicate-heading changes, and reordering.
- Keep an old target or explanatory fallback when feasible; document any exceptions for future editors.
- Test the rendered page after publishing, including old links, new links, target visibility, and ID uniqueness.
Conclusion
When an in-page link breaks after an edit, start with the old fragment and compare it with the destination’s rendered IDs. Preserving stable IDs—and leaving a useful fallback when content moves—helps readers reach the information they expected.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.