← Back to the Links & Media Reference
Lesson

Links & Media

Links are what make the web a web. This visual lesson covers the <a> tag and its five jobs, relative vs absolute paths, opening tabs safely, accessible link text — then bringing audio, video, and embeds into the page. Live demos throughout.

Step 1

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.

<a href="about.html"destination>About usvisible link text</a>
Visit our About page — that's a working link.
Step 2

Five kinds of links

The same <a> tag does five different jobs, depending on the href:

Goes tohref looks likeExample
Another websitehttps://…<a href="https://mdn.dev">MDN</a>
A page in your siteabout.html<a href="about.html">About</a>
A spot on the page#section-id<a href="#contact">Contact</a>
An emailmailto:…<a href="mailto:hi@x.com">Email</a>
A phone numbertel:…<a href="tel:+15551234">Call</a>
A text messagesms:…<a href="sms:+15551234">Text us</a>
A file to downloadfile.pdf + download<a href="cv.pdf" download>Résumé</a>
The #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"
ParameterDoes
?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) →
Encode the special characters. Spaces become %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.
Step 3

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"
Relative paths (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.”
Step 4

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>
Use it sparingly. Forcing new tabs takes control away from the user — many people prefer to decide themselves. Reserve _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”).
Step 5

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

Don't
To read the report,
<a href="report.pdf">click here</a>.

<a href="/sale">Read more</a>
Do
Read the
<a href="report.pdf">2026 annual report (PDF)</a>.

<a href="/sale">See this week's sale</a>
Why: screen-reader users often pull up a list of just the links on a page. A list of “click here, click here, read more” is useless — descriptive text tells them where each link actually goes.
Step 6

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.
Step 7

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>
Use this for self-hosted video. Add a <track> with captions for accessibility. For a background hero video add autoplay muted loop playsinline (it must be muted to autoplay).
Step 8

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>
Always give an <iframe> a title (screen readers announce it) and loading="lazy". Only embed sites you trust — you're running their page inside yours.
Step 9

Accessibility recap

Step 10

Links & media checklist

Step 11

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

Example company logo Visit our site — an image wrapped in a link.

Media samples

Audio

Video

Embedded video (iframe)

Back to top · © 2026 Workshop

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>
Spot the links: this one page uses an external link (new tab + 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.
Where next

Keep going