🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

HTML Media: Video, Audio, Images, and SVG

Web FoundationsđŸŸĸ Free Lesson

HTML Media

Modern HTML embeds video, audio, vector graphics, and resolution-aware images with no plugins — Flash is gone, and the elements that replaced it are better for accessibility, performance, and control. Each media element comes with a small set of attributes that do disproportionate work: preload policy for bandwidth, poster for the moment before playback, srcset for resolution selection, track for captions.

This lesson walks the practical surface of each element, then ties them together with the accessibility requirements that separate a polished media experience from a frustrating one.

Video: Sources, Tracks, and Fallbacks

The video element takes a controls attribute for the default player UI, a poster image shown before playback, and one or more source children so the browser can pick a codec it supports. Anything between the tags is fallback content for browsers that cannot play video at all.

<video
  controls
  width="640"
  height="360"
  poster="/img/lamination-poster.jpg"
  preload="metadata"
  playsinline
>
  <source src="/video/lamination.webm" type="video/webm">
  <source src="/video/lamination.mp4" type="video/mp4">
  <track
    kind="captions"
    src="/captions/lamination-en.vtt"
    srclang="en"
    label="English"
    default
  >
  <track
    kind="descriptions"
    src="/descriptions/lamination-en.vtt"
    srclang="en"
    label="Audio descriptions"
  >
  <p>
    Your browser cannot play embedded video.
    <a href="/video/lamination.mp4">Download the MP4</a> instead.
  </p>
</video>

preload="metadata" avoids downloading the whole file before the user presses play — the right default for pages with several videos; preload="auto" is justified only when playback is virtually certain. playsinline keeps iOS from hijacking the player into fullscreen. The width and height attributes reserve layout space so the page does not jump when the poster loads.

Captions ride in WebVTT files referenced by track elements. The default attribute makes one track start active. kind="descriptions" carries audio descriptions for visually impaired viewers; kind="subtitles" handles translation; kind="captions" is for deaf and hard-of-hearing viewers and includes sound effects and speaker cues.

Audio Without Plugins

Audio is the same pattern minus the visual surface. Multiple sources again — MP3 for universal coverage, Ogg or Opus where bitrate efficiency matters:

<figure>
  <figcaption>Episode 12 — Laminating dough at home</figcaption>
  <audio controls preload="none">
    <source src="/audio/episode-12.mp3" type="audio/mpeg">
    <source src="/audio/episode-12.opus" type="audio/opus">
    <p>
      Audio playback is not supported.
      <a href="/audio/episode-12.mp3">Download episode 12</a>.
    </p>
  </audio>
  <p><a href="/transcripts/episode-12.txt">Read the full transcript</a></p>
</figure>

The figure and caption pair keeps the player associated with its title. A transcript link is not optional decoration — it is the accessible alternative for anyone who cannot or prefers not to listen, and it is indexed content for search engines as a bonus.

Images: Attributes That Save Bandwidth

Beyond src and alt, the attributes that matter most in production are width/height (layout reservation, and the basis of zero-CLS layouts), loading="lazy" for offscreen images, decoding="async" to avoid blocking the main thread, and fetchpriority to mark hero images as important. srcset plus sizes lets the browser choose among resolution candidates:

<img
  src="/img/croissant-800.jpg"
  srcset="/img/croissant-400.jpg 400w,
          /img/croissant-800.jpg 800w,
          /img/croissant-1600.jpg 1600w"
  sizes="(min-width: 960px) 480px, 100vw"
  width="800"
  height="600"
  alt="Flaky croissants arranged on a baking tray"
  loading="lazy"
  decoding="async"
>

The w descriptors tell the browser each candidate's intrinsic width; sizes describes the layout so it can compute the effective size in device pixels and pick a match. Alt text remains the single most important attribute on the element: describe the information, not the pixels, and use an empty alt when the image is purely decorative.

The picture Element for Art Direction

When the shape of the image should change with the viewport — landscape on desktop, portrait on phones — srcset alone cannot help because it only varies resolution. picture stacks media-queried source elements in front of a plain img fallback:

<picture>
  <source
    media="(min-width: 960px)"
    srcset="/img/hero-wide.jpg"
    type="image/jpeg"
  >
  <source
    media="(max-width: 959px)"
    srcset="/img/hero-tall.jpg"
    type="image/jpeg"
  >
  <img
    src="/img/hero-fallback.jpg"
    alt="Baker scoring a sourdough loaf before it enters the oven"
    width="1200"
    height="800"
  >
</picture>

The img remains mandatory — it is the universal fallback and the element that carries alt text. Type-gated sources also enable modern formats: put an image/avif source before an image/webp source before the JPEG fallback, and capable browsers automatically take the smallest file.

SVG Inline vs External

Scalable Vector Graphics describe shapes as XML, so they stay crisp at any size and weigh kilobytes where photographs weigh megabytes. Inline SVG participates in the document: CSS can style its parts, and it can carry aria-hidden or role="img" with a title for assistive tech.

<svg
  role="img"
  aria-labelledby="rating-title"
  width="120"
  height="24"
  viewBox="0 0 120 24"
>
  <title id="rating-title">Rated 4 out of 5 by 312 customers</title>
  <use href="/sprites/icons.svg#star-filled" x="0"></use>
  <use href="/sprites/icons.svg#star-filled" x="24"></use>
  <use href="/sprites/icons.svg#star-filled" x="48"></use>
  <use href="/sprites/icons.svg#star-filled" x="72"></use>
  <use href="/sprites/icons.svg#star-empty" x="96"></use>
</svg>

Decorative icons should instead carry aria-hidden="true" so screen readers skip them. External SVG referenced through img or use is simpler to cache but cannot inherit page CSS — choose per use case.

Accessibility: Captions, Transcripts, and Alt Text

The through-line across every element is an alternative for each modality. Video gets captions (for sound-off and deaf viewers) and often a transcript; audio gets a transcript; images get alt text or an empty alt when decorative; SVG gets a title or aria-hidden. Autoplaying media must be avoided entirely — or at minimum muted with controls available — because unexpected sound is a WCAG failure and an irritation to everyone in earshot.

âš ī¸Captions are not auto-captions

Machine-generated captions are a starting point, not a deliverable. Brand names, technical terms, and speaker changes come out wrong often enough to make them unusable for deaf viewers. Review and correct captions before shipping, and timestamp them in standard WebVTT so players sync automatically.

Codecs, Loading Strategy, and Performance Budgets

Codec choice decides both file size and compatibility. For video, H.264 inside MP4 remains the universal baseline, with VP9 or AV1 inside WebM as size-efficient alternatives for capable browsers — list the modern sources first and the MP4 last so current clients take the smaller file. For audio, MP3 covers everything, while AAC and Opus trade size for quality inside narrower support envelopes. Images follow the same ladder: AVIF smallest, WebP next, JPEG or PNG as the universal floor, each source gated by a type declaration so older browsers skip cleanly past formats they cannot decode.

Loading strategy is a bandwidth budget. Use preload none, or omit the attribute, for videos that may never be played; metadata when the player interface needs the duration up front; auto only for a hero video that will autoplay muted. Lazy-load everything below the fold, but never lazy-load the candidate for largest contentful paint — the delay is punished in every performance score. The same logic applies to a page of stacked podcast players: metadata only until the listener commits to one. Captions and descriptions cost almost nothing — they are small text files — but they multiply with each language, and a stale translation erodes trust faster than none at all. Measure as you go: the network filmstrip and the layout-shift track in the performance panel will tell you whether the media choices hold the page to its budget or quietly blow it on every single visit.

💡One player, many files — pick the source order deliberately

Browsers evaluate source children top to bottom and stop at the first type they can decode. Put the most efficient modern format first, a widely compatible middle option second, and the universal baseline last, and every visitor automatically receives the smallest file their browser understands. Reorder that list whenever codec support shifts, and keep an eye on real-world byte savings in the network panel rather than trusting compatibility tables alone — device families and data-saver modes constantly change which format actually wins in the field.

Common Mistakes

Forgetting width and height on images and video

Fix: Declare both — the browser reserves space and cumulative layout shift stays near zero.

Relying on auto-generated captions without review

Fix: Edit captions for accuracy before shipping; treat them like any other published text.

Alt text that lists visual details irrelevant to context

Fix: Describe the information the image conveys here; empty alt for decoration.

preload='auto' on every video on a page

Fix: Use preload='metadata' by default so only the pressed video consumes bandwidth.

Key Takeaways

  • Video and audio take multiple sources plus fallback content between the tags.
  • track elements deliver captions, subtitles, and descriptions in WebVTT — review them for accuracy.
  • srcset with sizes handles resolution switching; picture adds media-based art direction and format selection.
  • Inline SVG is styleable and accessible with role=img and a title; hide decorative SVG with aria-hidden.
  • Every media modality needs an alternative: captions, transcripts, alt text.
  • preload='metadata' and lazy loading keep pages with media fast on mobile networks.

Extended Learning: Beyond the Basics

Key Concepts Summary

This lesson covers fundamental concepts that serve as building blocks for more advanced topics. Master these basics before moving to intermediate and advanced material.

Prerequisite Knowledge

Before studying this topic in depth, ensure you understand:

  • Basic definitions and terminology
  • Core formulas and their derivations
  • Common applications in real-world scenarios
  • Typical pitfalls and misconceptions

Step-by-Step Walkthrough

Let us work through a complete example to solidify understanding:

Step 1: Identify the problem type. Determine which category this problem falls into and which approach is most appropriate.

Step 2: Apply the relevant formula. Substitute known values into the appropriate equation, paying attention to units and constraints.

Step 3: Simplify and solve. Work through the algebra step by step, checking each intermediate result.

Step 4: Verify the answer. Check that the solution satisfies the original conditions and makes logical sense.

Common Mistakes to Avoid

  1. Misidentifying the problem type — Always start by categorizing the problem
  2. Incorrect formula application — Verify the formula applies to your specific case
  3. Unit errors — Always check units are consistent throughout
  4. Sign errors — Pay careful attention to positive and negative values
  5. Rounding too early — Keep full precision until the final answer
  6. Forgetting constraints — Check that solutions satisfy all given conditions

Real-World Applications

Understanding this concept is essential for:

  • Advanced problem solving in examinations
  • Building intuition for more complex topics
  • Developing analytical thinking skills
  • Applying mathematical reasoning to practical situations

Practice Exercises

  1. Basic: Solve 5 problems of increasing difficulty using the core concept.
  2. Intermediate: Apply the concept to word problems with multiple steps.
  3. Advanced: Combine this concept with 2-3 other topics in a comprehensive problem.
  4. Challenge: Create your own problem that requires this concept plus additional knowledge.

Interview and Exam Tips

  • Common question patterns: Identify which exam or interview formats test this topic
  • Time management: Practice completing problems within time constraints
  • Common traps: Know the typical mistakes examiners set as distractors
  • Verification strategy: Develop a quick method to check your answer

Related Topics

Quick Reference Card

ConceptFormula/RuleKey InsightCommon Use
Core DefinitionSee main textUnderstand the intuitionFoundation for all applications
Key FormulaSee main textMemorize the derivationDirect problem solving
Special CaseSee main textRecognize when it appliesSimplifies complex problems
Edge CaseSee main textKnow the limitationsAvoids errors

Further Reading

For students who want to go deeper:

  • Standard textbooks on the subject
  • Research papers applying this concept
  • Online courses with video explanations
  • Practice problem collections with detailed solutions
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-11-14

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Web Development Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement