WGU D276 practice

HTML5 Audio and Video: Supported Formats, Source Elements, Controls, and Fallback Content

The audio and video elements embed media without a plugin. Learn how the browser chooses among source children, which MIME types to use for MP4, WebM, and MP3, what controls and preload actually do, and why fallback content between the tags is not an error message. Includes practice questions with full explanations.

The <audio> and <video> elements embed sound and moving pictures directly in a page with no plugin and no third-party player. You point the element at a media file — either with a src attribute or with one or more <source> children — add controls so the visitor gets a play button, and the browser plays the first file it knows how to decode.

Two ways to point at a file

The short form puts the URL on the element itself: <video src="tour.mp4" controls></video>. The flexible form leaves src off the element and lists candidates as <source> children instead, so you can offer the same clip in more than one format:

<video controls width="640" height="360" poster="cover.jpg">
  <source src="tour.webm" type="video/webm">
  <source src="tour.mp4" type="video/mp4">
</video>

The browser walks that list in document order and stops at the first source it can play, so the order you write is your order of preference. The type value is a MIME type — optionally with a codecs parameter, like type="video/mp4; codecs=avc1.42E01E" — and it lets the browser rule out a format without requesting the file at all. Leave type off and the browser has to fetch the resource and inspect it before it can decide.

One rule worth memorizing: the two forms do not combine. If the <video> or <audio> element carries its own src, the browser loads that URL and never consults the <source> children. HTML's content model reflects this — <source> children are only permitted inside a media element that has no src attribute, so writing both is a conformance error even though browsers render the page without complaint.

Formats you can count on

  • MP4 — video/mp4. H.264 video with AAC audio; the safest single choice for broad support.
  • WebM — video/webm. Open format, VP8 or VP9 video with Vorbis or Opus audio.
  • Ogg — video/ogg. Older open format and the least widely supported of the three.
  • MP3 — audio/mpeg. Not audio/mp3: an MP3 file is a stream of MPEG-1 Audio Layer III frames, so MP3 is the exception to the extension-matches-type pattern.
  • WAV — audio/wav (audio/wave is the preferred registered spelling). Uncompressed, so files are large.
  • Ogg audio — audio/ogg. Vorbis or Opus.

Controls and friends

controls tells the browser to draw its default play, seek, and volume interface. It is a boolean attribute: writing it at all turns it on, so controls="false" still shows controls, and the only way to hide the player is to omit or remove the attribute. The same rule governs autoplay, loop, muted, and playsinline.

Other useful attributes are preload, which takes none, metadata, or auto (an empty value means auto) and is only a hint the browser may ignore; poster, a placeholder image for video; and width and height, which exist on <video> only and take absolute CSS pixel numbers, never percentages. An <audio> element without controls renders nothing visible at all.

Fallback content is for old browsers

Text or markup between the opening and closing tags is fallback content, shown only by browsers that do not understand the element at all. It is not an error message for a failed download or an unsupported codec — the specification tells supporting user agents not to show it. When loading fails, the media element fires an error event, and displaying a message in response is your job in script. Captions go in <track> elements, which use WebVTT files and must come after any <source> children.

Ready to check yourself? Work the questions below, then keep going with the D276 Web Development Foundations study guide.

Practice: Html5 Audio And Video

  1. You write a <video> element with two <source> children and a line of text between the opening and closing tags. The visitor's browser fully supports <video>, but it cannot decode either source file. What does the visitor see?

    • The text between the tags, because that content is the fallback for unplayable media
    • The poster image or an empty player area — the text between the tags is not displayed
    • The text between the tags, plus a browser-generated download link for the first source
    • A browser dialog offering to install a codec for the first listed format
    Show answer & explanation

    Correct answer: The poster image or an empty player area — the text between the tags is not displayed. Content inside a media element is intended for user agents that do not support <video> at all, and the HTML specification says user agents should not show it to the user. So when every source fails in a modern browser, you get the poster frame or an empty player box, never the fallback text. Option one is the trap: the text reads like an error message, but to react to a decode failure you have to handle the error event and render your own message.

  2. A browser encounters <video controls> containing a <source> for clip.webm followed by a <source> for clip.mp4, and it can play both formats. How does it decide which file to load?

    • It downloads both and plays whichever finishes buffering first
    • It compares the two files and loads the smaller one to save bandwidth
    • It plays the MP4, because MP4 always outranks WebM in the selection algorithm
    • It tests the sources in document order and uses the first one it can play, ignoring the rest
    Show answer & explanation

    Correct answer: It tests the sources in document order and uses the first one it can play, ignoring the rest. The resource selection algorithm evaluates candidate sources in document order and stops at the first one it can render, so the order you write them in is your order of preference — here, WebM wins. A type attribute simply lets the browser rule out a format before requesting the file. Browsers do not fetch every source in parallel, and there is no built-in ranking that favors MP4 over other container formats.

  3. Which type value is the registered MIME type for an MP3 file inside a <source> element?

    • type="audio/mp3"
    • type="audio/mpeg"
    • type="audio/mpeg3"
    • type="audio/x-mp3"
    Show answer & explanation

    Correct answer: type="audio/mpeg". An MP3 file is a stream of MPEG-1 Audio Layer III frames rather than a distinct container, and its registered MIME type is audio/mpeg. audio/mp3 is the tempting answer because audio/ogg, audio/wav, and video/mp4 all echo their file extensions, but MP3 breaks that pattern. audio/mpeg3 and audio/x-mp3 are unregistered legacy strings that a browser has no obligation to recognize, so using the registered type keeps the format check reliable.

  4. Given <video src="tour.mp4" controls> with a single <source> child pointing at tour.webm, what happens in a browser that supports both formats?

    • tour.webm plays, because <source> children always override the parent's src
    • Neither file plays, because the browser refuses markup that mixes src with <source> children
    • tour.mp4 plays, because a src on the media element makes the <source> children irrelevant
    • tour.mp4 plays first and tour.webm plays after it, as a two-item playlist
    Show answer & explanation

    Correct answer: tour.mp4 plays, because a src on the media element makes the <source> children irrelevant. When the media element itself carries a src attribute, resource selection runs in "attribute" mode: the browser loads that URL and never consults the <source> children. Nothing breaks at runtime — tour.mp4 plays normally — though a conformance checker will flag the <source> child, since HTML permits <source> only inside a media element with no src. Media elements also have no playlist behavior, so a second file never queues up on its own.

  5. A student writes an <audio> element with a src and the attribute controls="false", expecting to hide the player. What actually happens?

    • The default player controls still appear, because controls is a boolean attribute
    • The player is hidden and the audio begins playing silently in the background
    • The document fails validation and the browser drops the element from the DOM
    • The controls appear but are disabled, so clicking them does nothing
    Show answer & explanation

    Correct answer: The default player controls still appear, because controls is a boolean attribute. controls is a boolean attribute: its mere presence turns the feature on, and the string assigned to it — "false", "no", or anything else — is never examined. The only way to hide the default player is to leave the attribute off or remove it through the DOM. Note too that an <audio> element without controls renders nothing visible, and it will not start playing on its own without autoplay or a script.

  6. You want to add English captions to a <video> element that already has two <source> children. Which approach is correct?

    • A <track kind="captions" src="captions.srt" srclang="en"> element placed before the <source> elements
    • A <caption src="captions.vtt" lang="en"> element placed inside the <video> element
    • A third <source kind="captions" src="captions.vtt" srclang="en"> listed after the media sources
    • A <track kind="captions" src="captions.vtt" srclang="en" label="English" default> element placed after the <source> elements
    Show answer & explanation

    Correct answer: A <track kind="captions" src="captions.vtt" srclang="en" label="English" default> element placed after the <source> elements. Timed text belongs in a <track> element, which the content model places after any <source> children, and the file has to be WebVTT — browsers do not natively read .srt subtitle files. There is no <caption> element for media; HTML's <caption> is the table caption. And <source> only ever points at a media resource, so it cannot carry caption data or a srclang.

A worked example

Here is a video block that covers the realistic cases — two formats, a poster, captions, and fallback markup for a browser from another era:

<video controls preload="metadata" width="640" height="360"
       poster="lecture-cover.jpg">
  <source src="lecture.webm" type="video/webm">
  <source src="lecture.mp4" type="video/mp4">
  <track kind="captions" src="lecture-en.vtt" srclang="en"
         label="English" default>
  <p>Your browser can't play embedded video.
     <a href="lecture.mp4">Download the MP4</a>.</p>
</video>

Read that top to bottom the way the browser does: sources first (pick one), then tracks (load captions for the chosen video), then fallback content (ignore it, since I understand <video>). That order is not stylistic — the content model requires <source> children before <track> children.

Mistakes people actually make

  • Treating fallback content as an error message. This is the single most common misreading. Fallback appears only when the element itself is unrecognized. A broken URL or an unsupported codec produces an empty player, not your friendly paragraph.
  • Expecting autoplay to work. Browsers block autoplay of media with an audible track. Adding muted alongside autoplay is normally what lets playback start, which is why background hero videos are silent — though the exact policy varies by browser and by how much the user has interacted with the site.
  • Writing audio/mp3. The registered type is audio/mpeg. Every other common format echoes its extension, so this one gets typed wrong constantly.
  • Keeping src on the element after adding <source> children. The children become dead markup and the document stops conforming. Delete the src when you convert to the multi-source pattern.
  • Forgetting controls on <audio>. The element occupies no visible space, so the page looks like nothing was added at all.
  • Using percentages in width. Those attributes take absolute CSS pixel numbers; do responsive sizing in a stylesheet with max-width: 100%.

Reasoning about the tricky cases

When a question describes markup and asks what the user sees, resolve it in three steps. First ask which resource wins: an element-level src beats <source> children outright, and among children the first playable one wins. Then ask what is rendered: <video> always occupies a box, while <audio> shows something only with controls. Finally ask what the fallback is doing: in any modern browser, nothing.

Boolean attributes deserve one more pass, because they show up in disguised forms. controls, autoplay, loop, muted, and a <track> element's default are on when written and off when absent — the assigned value is never consulted, so removing the attribute is the only way to turn the feature off. By contrast, preload is an enumerated attribute whose value carries meaning: none, metadata, and auto give the browser different hints about how much to fetch up front, and the browser is free to ignore the hint.

When you want to confirm a detail, go to a primary source rather than a tutorial — the MDN reference for <video> is the fastest place to settle an attribute argument, and the WHATWG HTML standard's media chapter settles behavior questions. Then run more D276 practice questions to see whether the rule sticks.

Want someone to walk you through this?

Book 1-on-1 prep for WGU D276 — original coaching, never exam content.

Stuck on this topic? WhatsApp us on +1 646 980 4914.

Working through the whole course? Read the full WGU D276 study guide, or see every WGU D276 practice topic.

More WGU D276 practice

Html Document Structure

The five lines at the top of every HTML file are not decoration. Here is what the doctype, the html/head/body split, meta charset, and the viewport tag each do — why the browser misbehaves when you leave one out, and how to reason about the cases that trip people up.

Semantic Structure Tags

Semantic structure tags describe what a block of content is, not how it looks. This lesson explains the difference between article, section, aside, main, nav, header and footer — including the syndication test that settles article vs. section, the strict placement rules for main, and how header and footer change meaning depending on where they sit — then gives you practice questions with worked explanations.

Headings Text Links Lists

Heading elements rank content instead of sizing it, strong and em carry meaning that b and i do not, a fragment link points at an element's id, and ul, ol, and dl each describe a different kind of grouping. Work through how each one behaves, then test yourself on the cases people actually get wrong.

Images And Alt Text

An image starts with one element and one honest description. From there, srcset, sizes, and picture answer a single question: which file should the browser download on this screen? This guide walks through alt text, figure and figcaption, resolution switching, and art direction, then gives you six practice questions with full explanations.

Html Tables

A plain-English walkthrough of HTML table markup for WGU D276: how table, caption, thead, tbody, tr, th and td nest, what the scope attribute actually does for assistive technology, and how colspan and rowspan reshape the grid — plus practice questions with worked explanations.

Forms And Input Types

A form's action says where the data goes and its method says how it travels there. Work through the pieces that carry the data — name attributes, input types, labels tied to ids, select options, textarea content and the button that submits it all — then test yourself on the details that trip people up.