An anchor with href creates a link that can be followed, copied, opened in a new tab, and reached by keyboard.
HTML anchors: use href for navigation and stable fragment targets
Use it for a real task
A receipt index links to a specific record and to an explanation lower on the same page. The fragment target is an id on the destination heading. Relative paths keep the example on the same origin, while the visible link text says what will open rather than relying on surrounding text.
<nav aria-label="Receipt navigation">
<a href="/receipts/R-47">Open receipt R-47</a>
<a href="#export-policy">Read the export policy</a>
</nav>
<section aria-labelledby="export-policy">
<h2 id="export-policy">Export policy</h2>
<p>Only approved receipts are included.</p>
</section>What the markup guarantees
The path route needs a server that serves that record; HTML alone does not create the endpoint. Use a button for a local action such as submitting a form, and use an anchor for navigation.
Cost and limits
Links require no JavaScript. Broken paths and duplicate ids are the practical failure modes, so check internal destinations as part of publishing.
Common Mistakes
- Do not use href='#' as a fake button.
- A fragment id must be unique within its document.
- Describe the destination; repeated 'click here' labels lose context.
Connected lessons
- HTML link versus button: navigation and actions have different contracts
- HTML landmarks: give navigation, main content, and page edges clear owners
- HTML document skeleton: declare language, encoding, and a real title
Related: HTML character references: escape data before inserting it into markup.
Related: HTML landmarks: give navigation, main content, and page edges clear owners.
Related: HTML image alt text: describe function or information, not pixels alone.
Related: HTML link versus button: navigation and actions have different contracts.
Continue with HTML global attributes: keep id, class, and data-* jobs separate.
Related: HTML base: change how every relative URL resolves.
Related: HTML links in a new tab: preserve context without hiding the action.
Related: HTML download links: distinguish a file transfer from page navigation.
Related: HTML link referrer policy: control what a navigation reveals.
Further CSS decisions
Rendering decisions
Related CSS decisions
Continue with the connected Web Development lesson: URLs and origins: separate location, query, and fragment.
