Href supplies a URL reference. On an anchor with href, it creates a hyperlink to a document, fragment, or other resource. It also appears on elements such as link and base with different purposes.
Navigate to a real section
This link points to a heading ID inside the standalone document. It does not use href=”#” as a substitute for a missing destination.
HTML and CSS
HTML
<a href="#practice">Read the practice section</a>
<section id="practice">
<h2>Practice section</h2>
<p>The link destination exists.</p>
</section>
CSS
section {
margin-top: 2rem;
padding: 1rem;
background: #eff6ff;
}
Edit HTML or CSS to update the preview as you type. Copy code snippet copies the selected tab. Preview spacing and font defaults are not included.
Choose the right URL form
A same-document #practice matches a case-sensitive ID. A relative lesson.html resolves against the document’s base URL; /css/display.html starts at the current origin’s root; a full https URL names an origin too. Mailto and tel links request a handler and do not guarantee a message or call is sent.
Href on link describes a related resource, such as a stylesheet; it does not create a visible text link. Href on base changes relative URL resolution for the document. These are separate element behaviors, so check the element rather than treating href as universal navigation.
Links navigate; buttons act
Use a real anchor destination when moving somewhere. Use button for opening a dialog, toggling a control, or performing an action. An a without href is not an ordinary keyboard-operable hyperlink. Do not use href=”#” plus click cancellation as your default button pattern.
Give links descriptive text and visible focus. Underlines are a useful cue in prose; browser default colors can be changed by user or author styles. If opening a new browsing context is necessary, explain that behavior and consider the relevant target/rel rules.
Learn a, button, base, and relative paths.
Sources
Reference 1 Reference 2 Reference 3 provide the technical details and current compatibility information.