The anatomy of a link
A link is an anchor — the <a> tag. The href attribute (“hypertext reference”) says where it goes; the text between the tags is what the user sees and clicks.
Five kinds of links
The same <a> tag does five different jobs, depending on the href:
| Goes to | href looks like | Example |
|---|---|---|
| Another website | https://… | <a href="https://mdn.dev">MDN</a> |
| A page in your site | about.html | <a href="about.html">About</a> |
| A spot on the page | #section-id | <a href="#contact">Contact</a> |
| An email | mailto:… | <a href="mailto:hi@x.com">Email</a> |
| A phone number | tel:… | <a href="tel:+15551234">Call</a> |
| A text message | sms:… | <a href="sms:+15551234">Text us</a> |
| A file to download | file.pdf + download | <a href="cv.pdf" download>Résumé</a> |
#section-id link jumps to the element with that id on the page — that's exactly how the table of contents at the top of this lesson works. Add scroll-behavior: smooth to animate the jump.Pre-fill the subject & body of an email link
A plain mailto: just opens a blank email. You can pre-fill the subject, body, and even cc/bcc by adding them after a ? — the first one starts with ?, and each extra one is joined with &.
<a href="mailto:hello@example.com?subject=Website%20question&body=Hi%20Dr.%20G,">Email me</a> Add cc and bcc the same way: href="mailto:hello@example.com?cc=team@example.com&bcc=boss@example.com&subject=Hi"
| Parameter | Does |
|---|---|
| ?subject= | Pre-fills the subject line |
| &body= | Pre-fills the message text |
| &cc= / &bcc= | Adds carbon-copy / blind-copy recipients |
Live example — this opens your email app with the subject and message already filled in:
Email Dr. G (pre-filled) →%20 and a line break is %0D%0A (carriage-return + line-feed) — that's URL encoding. Most editors or an online “mailto link generator” will do it for you. And remember: this only opens the user's email app pre-filled — it doesn't send anything automatically.Relative vs absolute paths
For links and media inside your own site, the path tells the browser how to find the file relative to the current page.
Folder structure: my-site/ ├─ index.html ├─ about.html ├─ images/ │ └─ logo.png └─ blog/ └─ post.html From index.html: href="about.html" same folder src="images/logo.png" into a subfolder href="blog/post.html" From blog/post.html, to get back out: href="../about.html" ../ = go up one folder src="../images/logo.png"
about.html, ../images/logo.png) point within your own project — use these for your pages and assets. Absolute URLs (https://othersite.com/…) point to a full web address — use these for external sites. ../ means “go up one folder.”Opening links in a new tab — safely
target="_blank" opens a link in a new tab. When you do, also add rel="noopener noreferrer" — without it, the new page can script your original tab (a security risk) and gets referrer info.
<a href="https://example.com" target="_blank" rel="noopener noreferrer">Opens in a new tab</a>
_blank for cases where leaving the current page would lose their work (like a form). When you do use it, warn users (an icon or “opens in new tab”).Link states & writing good link text
Links have four states you can style. The focus ring (for keyboard users) is the one people forget — never remove it.
a { color: #2563eb; } a:visited { color: #7c3aed; } a:hover { text-decoration: underline; } a:focus-visible { outline: 3px solid #93c5fd; } keyboard focus ring
Write link text that makes sense on its own
To read the report, <a href="report.pdf">click here</a>. <a href="/sale">Read more</a>
Read the <a href="report.pdf">2026 annual report (PDF)</a>. <a href="/sale">See this week's sale</a>
Audio
The <audio> element plays sound with built-in controls — one tag, no JavaScript. Press play.
<audio controls preload="none"> <source src="clip.mp3" type="audio/mpeg"> <source src="clip.ogg" type="audio/ogg"> Your browser doesn't support audio. </audio>
controls shows the player; preload="none" waits to download until play; loop repeats. Offer two formats (mp3 + ogg) so every browser has one it can play.Video
The <video> element gives you play/pause, scrubber, volume, and fullscreen. Add a poster so something shows before play. Press play.
<video controls preload="none" poster="thumb.jpg"> <source src="movie.mp4" type="video/mp4"> <track kind="captions" src="captions.vtt" srclang="en"> </video>
<track> with captions for accessibility. For a background hero video add autoplay muted loop playsinline (it must be muted to autoplay).Embeds & iframes
An <iframe> drops another page inside yours — a YouTube video, a Google Map, a form. Wrap it in a 16:9 box so it scales responsively.
.embed { position: relative; aspect-ratio: 16 / 9; } .embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; } <iframe src="https://www.youtube.com/embed/VIDEO_ID" title="Embedded video" loading="lazy" allowfullscreen></iframe>
<iframe> a title (screen readers announce it) and loading="lazy". Only embed sites you trust — you're running their page inside yours.Accessibility recap
- Descriptive link text — never “click here.”
- Keep the focus ring so keyboard users can see where they are.
- Warn about new tabs and non-HTML targets (“(PDF),” “opens in new tab”).
- Caption your videos with a
<track>, and provide transcripts for audio. - Title every
<iframe>so its purpose is announced. - Don't autoplay sound — let people choose to play.
Links & media checklist
- Every link has a clear
hrefand descriptive text - Internal links use relative paths; external links use full
https://URLs -
target="_blank"always paired withrel="noopener noreferrer" - The keyboard focus ring is visible (not removed)
-
<audio>/<video>havecontrols; video has aposterand captions - Embeds are in a responsive 16:9 wrapper with a
title - Nothing autoplays with sound
Everything on one page
Here's one small page that uses every kind of link and every media element from this lesson — a workshop resources page. First the rendered result, then the exact code below. See how many link types you can spot.
The rendered page
Workshop Resources
Reading list
Start with the official docs on MDN Web Docs ↗ (an external link that opens in a new tab). Then review our About page for context, and jump down to the media samples below.
Download the syllabus (PDF) — a download link.
Get in touch
- Email: hello@example.com
- Call: (555) 123-4567
- Text: Send a text
Visit our site
— an image wrapped in a link.
Media samples
Audio
Video
Embedded video (iframe)
The code (styling omitted so the links & media stand out)
<header>
<h1>Workshop Resources</h1>
<nav aria-label="Primary">
<a href="#reading">Reading</a> <!-- jump to a spot on the page -->
<a href="#contact">Contact</a>
<a href="#media">Media</a>
</nav>
</header>
<main>
<section id="reading">
<h2>Reading list</h2>
<p>Start with the official docs on
<!-- external link, new tab, done safely -->
<a href="https://developer.mozilla.org"
target="_blank" rel="noopener noreferrer">MDN Web Docs ↗</a>.
Then review our
<a href="about.html">About page</a> <!-- relative link -->
and jump to the
<a href="#media">media samples below</a>.</p>
<!-- download link -->
<p><a href="syllabus.pdf" download>Download the syllabus (PDF)</a></p>
</section>
<section id="contact">
<h2>Get in touch</h2>
<ul>
<li>Email:
<a href="mailto:hello@example.com?subject=Workshop%20question">hello@example.com</a></li>
<li>Call: <a href="tel:+15551234567">(555) 123-4567</a></li>
<li>Text: <a href="sms:+15551234567">Send a text</a></li>
</ul>
<!-- an image wrapped in a link -->
<p>
<a href="https://example.com" target="_blank" rel="noopener noreferrer">
<img src="logo.png" alt="Example company logo"> Visit our site
</a>
</p>
</section>
<section id="media">
<h2>Media samples</h2>
<h3>Audio</h3>
<audio controls preload="none">
<source src="clip.mp3" type="audio/mpeg">
Your browser doesn't support audio.
</audio>
<h3>Video</h3>
<video controls preload="none" poster="thumb.jpg">
<source src="movie.mp4" type="video/mp4">
<track kind="captions" src="captions.vtt" srclang="en">
Your browser doesn't support video.
</video>
<h3>Embedded video (iframe)</h3>
<div class="embed">
<iframe src="https://www.youtube.com/embed/VIDEO_ID"
title="Embedded sample video"
loading="lazy" allowfullscreen></iframe>
</div>
</section>
</main>
<footer>
<p>Back to <a href="#top">top</a> · © 2026 Workshop</p>
</footer>
rel="noopener noreferrer"), a relative internal link, three same-page anchor links, a mailto: (with a pre-filled subject), a tel:, an sms:, a download link, and an image wrapped in a link — plus <audio>, <video> (with a captions <track>), and a responsive <iframe> embed.