How do I create an internal link to a section of the same page?
Quick answer
Add a concise, descriptive id to the section you want to reach, then put that exact value after # in the link’s href. For example, <h2 id="setup">Setup</h2> pairs with <a href="#setup">Go to Setup</a>. Keep the values matched, use distinct ids for intended destinations, and check the link in the rendered page. A fragment addresses content within a page. [S1][S2]
The question, the details, the next step.
A practical checklist
Add a concise, descriptive
idto the destination element.Set the link’s
hrefto#followed by the exact same id.Give each intended destination its own id.
After editing a heading, confirm the id and link still match.
Click the link in the rendered page and check that it reaches the intended section.
A few more useful answers
Does the visible link text have to match the destination id?
No. The visible link text can be different. The fragment after # must match the destination element’s id.
Will changing a heading necessarily break its link?
Not if the destination keeps its custom id and the link still points to it. Stable custom anchors can help prevent links breaking when headings are revised. [S1]
Does a fragment create a separate page?
No. A fragment addresses content within a page; it is not a replacement for a distinct page URL. [S2]
Sources
References used for this guide.
- [S1] Make headings into link targets developers.google.com · Checked
- [S2] Frequently asked questions about JavaScript and links developers.google.com · Checked
