Links and anchors
Artifact: Internal + external links wired correctly
1. Principle
A link is the <a> tag. It is the single most important tag on the web — without links, the web is a pile of disconnected documents.
The <a> tag has one essential attribute: href (short for hypertext reference). That's where the link goes.
<a href="https://github.com/you">My GitHub</a>
Three kinds of href:
| Type | Example | Goes to |
|---|---|---|
| External URL | https://github.com/you | A page on another site |
| Relative path | about.html | A file in the same folder |
| Anchor | #contact | A section on the same page |
2. Do (you try)
Inside your <h2>Contact</h2> paragraph, add a link to your GitHub (or any URL — replace with whatever's real for you).
Inside your <h2>About</h2> paragraph, add a link to your LinkedIn or a personal site.
After your <h1>, add a small inline navigation with links to each section of the page.
<body>
<h1>Your Name</h1>
<nav>
<a href="#about">About</a> ·
<a href="#projects">Projects</a> ·
<a href="#contact">Contact</a>
</nav>
<h2 id="about">About</h2>
<p>
I am a developer. You can find me on
<a href="https://github.com/your-username" target="_blank" rel="noopener noreferrer">GitHub</a>.
</p>
<h2 id="projects">Projects</h2>
<p>Coming in unit 1.5.</p>
<h2 id="contact">Contact</h2>
<p>
Email me at <a href="mailto:you@example.com">you@example.com</a>.
</p>
</body>Note the id="about" on the heading and the href="#about" in the nav — that's the anchor link, pointing to that id.
Save and refresh.
3. Verify (how you know)
Three click tests:
- Click "About" in the nav. The browser scrolls down to the About section. URL bar gains
#aboutat the end. - Click the GitHub link. It opens — in a new tab because of
target="_blank". - Click the email link. Your mail app (or browser's default) tries to compose a new email to that address.
If any of these don't work:
- Scroll doesn't happen → the
idon the heading doesn't match thehref(typo, capitalization). - GitHub opens in the same tab → you forgot
target="_blank". - Email link does nothing → it might still be correct; depends on your OS settings.
4. Reference
Locked. Try it yourself first.