auditmysitev2.0.2

Autoplaying sound plays longer than three seconds without a control

media/audio-autoplay-measured

WCAG success criterion
1.4.2 (level A)
Outcome class
Automatic. An automated check that can report a confirmed violation.
Area
Accessibility, Visual Presentation
Default severity
medium
axe-core rule
media/audio-autoplay-measured

Why we flag this

Sound that starts on its own drowns out screen reader speech, and nothing on the element stops it.

Measured in the browser: an audio or video element with autoplay plays, is not muted, has an audio track, lasts more than three seconds and has no usable controls.

What the rule checks

Scope. <audio autoplay> and <video autoplay> in the document, open shadow roots and same-origin frames whose playback the browser measured (Rendering::media_playback, accessibility::probes): metadata within the budget and autoplay no longer waiting for data.

Expectation. Fails when the measured medium plays (paused false; ended counts as played), is not muted, has an audio track heard above -60 dBFS while it plays, lasts more than three seconds (a media fragment #t=a,b shortens it, loop or a stream never ends) and has no usable native controls: the sound drowns out a screen reader and nothing on the element stops it. Paused, muted, three seconds or less, no audio track, or native controls pass. An audio track that stays silent while measured (a video with an empty track) or a medium of another origin (no capture) gives a review, as does an unknown duration. A control mechanism built by the page's script is not recognised (ACT 80f0bf Passed Example 3 fails here). Chrome runs with autoplay with sound allowed, the worst case a visitor can get. A medium without a measurement stays with media/audio-autoplay; a page whose autoplay media were all unmeasured records this rule as not run (CapabilityMissing), never as a pass.

Source. WCAG 2.2 SC 1.4.2 Audio Control; HTML §4.8.11 media elements (autoplay, paused, muted, duration, media fragments); ACT 80f0bf

Detection: shared; needs dom, interaction, frames.

Failing example

The check reports a violation here. Corpus case media_autoplay_measured, element audio#tone. The page may contain further findings for other rules.

media_autoplay_measured.htmlHTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Autoplaying sound, measured</title>
</head>
<body>
<header>
  <a href="#main" style="display: inline-block; min-width: 44px; min-height: 44px; line-height: 44px; padding: 0 8px">Skip to main content</a>
  <nav aria-label="Main"><a href="#main" aria-current="page" style="display: inline-block; min-width: 44px; min-height: 44px; line-height: 44px; padding: 0 8px">Radio</a></nav>
</header>
<main id="main">
  <h1>Station jingles</h1>
  <!-- WCAG 1.4.2, ACT 80f0bf: 30 s of audible tone, no controls, not muted. -->
  <audio id="tone" autoplay data-seconds="30" data-hz="440"></audio>
  <!-- Native controls pause it: passes. -->
  <audio id="tone-controls" autoplay controls data-seconds="30" data-hz="440"></audio>
  <!-- Muted: passes. -->
  <audio id="tone-muted" autoplay muted data-seconds="30" data-hz="440"></audio>
  <!-- Three seconds at most: passes. -->
  <audio id="jingle" autoplay data-seconds="2" data-hz="660"></audio>
  <!-- An audio track of silence: whether it is heard is not measured, a review. -->
  <audio id="silence" autoplay data-seconds="30" data-hz="0"></audio>
  <p>The jingles are generated in the page as WAV files (same origin, so the audio track can be measured).</p>
</main>
<footer><p>Footer text</p></footer>
<script>
  // 16-bit mono PCM at 8 kHz: a sine of data-hz for data-seconds (0 Hz is silence).
  function wav(seconds, hz) {
    var rate = 8000, n = seconds * rate, buf = new ArrayBuffer(44 + n * 2), v = new DataView(buf);
    function str(o, s) { for (var i = 0; i < s.length; i++) v.setUint8(o + i, s.charCodeAt(i)); }
    str(0, 'RIFF'); v.setUint32(4, 36 + n * 2, true); str(8, 'WAVE'); str(12, 'fmt ');
    v.setUint32(16, 16, true); v.setUint16(20, 1, true); v.setUint16(22, 1, true);
    v.setUint32(24, rate, true); v.setUint32(28, rate * 2, true); v.setUint16(32, 2, true);
    v.setUint16(34, 16, true); str(36, 'data'); v.setUint32(40, n * 2, true);
    for (var i = 0; i < n; i++) v.setInt16(44 + i * 2, Math.round(Math.sin(2 * Math.PI * hz * i / rate) * 12000), true);
    return URL.createObjectURL(new Blob([buf], { type: 'audio/wav' }));
  }
  document.querySelectorAll('audio[data-seconds]').forEach(function (a) {
    a.src = wav(Number(a.dataset.seconds), Number(a.dataset.hz));
  });
</script>
</body>
</html>

Passing example

The check passes here and reports nothing. Corpus case media_autoplay_measured, element audio#tone-controls. The page may contain further findings for other rules.

media_autoplay_measured.htmlHTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Autoplaying sound, measured</title>
</head>
<body>
<header>
  <a href="#main" style="display: inline-block; min-width: 44px; min-height: 44px; line-height: 44px; padding: 0 8px">Skip to main content</a>
  <nav aria-label="Main"><a href="#main" aria-current="page" style="display: inline-block; min-width: 44px; min-height: 44px; line-height: 44px; padding: 0 8px">Radio</a></nav>
</header>
<main id="main">
  <h1>Station jingles</h1>
  <!-- WCAG 1.4.2, ACT 80f0bf: 30 s of audible tone, no controls, not muted. -->
  <audio id="tone" autoplay data-seconds="30" data-hz="440"></audio>
  <!-- Native controls pause it: passes. -->
  <audio id="tone-controls" autoplay controls data-seconds="30" data-hz="440"></audio>
  <!-- Muted: passes. -->
  <audio id="tone-muted" autoplay muted data-seconds="30" data-hz="440"></audio>
  <!-- Three seconds at most: passes. -->
  <audio id="jingle" autoplay data-seconds="2" data-hz="660"></audio>
  <!-- An audio track of silence: whether it is heard is not measured, a review. -->
  <audio id="silence" autoplay data-seconds="30" data-hz="0"></audio>
  <p>The jingles are generated in the page as WAV files (same origin, so the audio track can be measured).</p>
</main>
<footer><p>Footer text</p></footer>
<script>
  // 16-bit mono PCM at 8 kHz: a sine of data-hz for data-seconds (0 Hz is silence).
  function wav(seconds, hz) {
    var rate = 8000, n = seconds * rate, buf = new ArrayBuffer(44 + n * 2), v = new DataView(buf);
    function str(o, s) { for (var i = 0; i < s.length; i++) v.setUint8(o + i, s.charCodeAt(i)); }
    str(0, 'RIFF'); v.setUint32(4, 36 + n * 2, true); str(8, 'WAVE'); str(12, 'fmt ');
    v.setUint32(16, 16, true); v.setUint16(20, 1, true); v.setUint16(22, 1, true);
    v.setUint32(24, rate, true); v.setUint32(28, rate * 2, true); v.setUint16(32, 2, true);
    v.setUint16(34, 16, true); str(36, 'data'); v.setUint32(40, n * 2, true);
    for (var i = 0; i < n; i++) v.setInt16(44 + i * 2, Math.round(Math.sin(2 * Math.PI * hz * i / rate) * 12000), true);
    return URL.createObjectURL(new Blob([buf], { type: 'audio/wav' }));
  }
  document.querySelectorAll('audio[data-seconds]').forEach(function (a) {
    a.src = wav(Number(a.dataset.seconds), Number(a.dataset.hz));
  });
</script>
</body>
</html>

This page is generated from the rule catalogue and the rule contracts; see therule overview for how the outcome classes are derived.