Module 5: Links and Navigation
The Anchor Element and href
Create a real hyperlink and understand why the href attribute matters.
The anchor element creates a hyperlink when it has an href attribute. The destination may be another page, a section of the current page, an email address, or another supported URL scheme.
<a href="https://developer.mozilla.org/">Read the MDN documentation</a>
<a href="/learn/html/">Continue the HTML course</a>
Link text should make sense when read on its own. “Read the MDN guide to HTML forms” is more helpful than “click here”. Descriptive text tells visitors where they will go and gives assistive technology a useful accessible name.
A link is not a button. Use an anchor when the action is navigation. Use a button when the user triggers an action on the current page, such as opening a dialog, submitting a form, or changing a setting. Styling can make them look similar, but their behavior and keyboard expectations are different.
A link can contain text, an image with meaningful alternative text, or both. Avoid placing unrelated interactive controls inside a link, and do not nest anchors inside anchors.