日本語

How to Fix the Lighthouse “video captions” Warning

​​Lighthouse​Accessibility,HTML,WebVTT

If Lighthouse's accessibility audit flags a <video> element for missing captions, create a WebVTT caption file (.vtt) and add <track kind="captions"> inside the <video>. The warning goes away. This audit is there so that people who are deaf or hard of hearing, or who watch where they cannot play sound, can follow the dialogue and sound effects as text.

html
<!-- Flagged -->
<video src="cat.webm" controls width="640" height="360"></video>

<!-- Fixed -->
<video controls width="640" height="360">
  <source src="cat.webm" type="video/webm">
  <track kind="captions" src="captions.vtt" srclang="ja" label="日本語" default>
</video>

In my test environment, I prepared 10 pages that differ in how the <track> is written, and checked both Lighthouse's result and whether the captions loaded in a browser.

Note

The test environment was Ubuntu 24.04, Node.js 22.23.5, and Lighthouse 13.6.0 (the CLI installed with npm; the bundled axe-core is 4.14.0). Lighthouse ran in headless Google Chrome for Testing 158. I used the default mobile settings and ran only the accessibility category. Caption loading and screenshots were done in headless Chromium 158.0.8127.36, which ships with Playwright 1.63.0. The videos were 6-second test clips made with ffmpeg. I did not test the Lighthouse panel in DevTools, PageSpeed Insights, or videos embedded in iframes from YouTube and similar sites.

Being flagged does not lower the score

I served a page with a caption-less video using python3 -m http.server and ran the following. The CHROME_PATH environment variable points to the Chrome for Testing executable I used. --no-sandbox is there so Chrome can start in my test environment.

bash
npx lighthouse http://127.0.0.1:8000/none.html \
  --only-categories=accessibility --locale=ja \
  --output=json --output=html --output-path=./out/none-ja \
  --chrome-flags="--headless=new --no-sandbox" --quiet

The Japanese report showed the following.

Japanese Lighthouse report. The accessibility score is 100. Below it, under the audio and video group, there is an item with a grey circle. Its title says that a `<video>` element contains a `<track>` element with `[kind="captions"]`. The labels in the report are in Japanese. Expanding the item shows "no score" and lists the caption-less video tag as the problem element
Lighthouse report for a page with a caption-less video

Two things in this screen are easy to misread.

First, the score stays at 100. The item has a grey circle and shows "no score". I wrote a small script that pulls the video-caption value out of the JSON report. It returned the following. scoreDisplayMode is informative, and the weight is 0.

text
accessibility score: 100 | video-caption: score=1 scoreDisplayMode=informative weight=0 group=a11y-audio-video | score=0 audits: (none)
  title: `<video>` 要素に `[kind="captions"]` が指定された `<track>` 要素が含まれています
  node: <video src="cat.webm" controls="" width="640" height="360"> 
  Fix all of the following:
    Check that captions are available for the element

The Lighthouse 13.6.0 config gives video-caption a weight of 10. However, because the video-caption audit is in informative mode, the scoring code replaces its weight with 0, so it is not counted. The score=1 in the output does not mean the audit passed. Informative audits are set to a score of 1.

Second, the item title is worded as a statement that the video contains a <track> element, which is how a passing audit is phrased. Judging by the title alone, a video without captions looks fine. To tell whether the audit flagged it, look at whether <video> appears under the problem elements when you expand the item, not at the title.

Why it is "informative"

Lighthouse hands this check to the axe-core rule video-caption. In axe-core 4.14.0, the caption check looks for <track> elements inside <video>, and passes if one has kind set to captions. If there is none, it does not fail. It returns "incomplete" (needs manual review). The source has a comment saying that without a <track>, the video might provide captions another way. So a missing <track> alone is not treated as proof that there are no captions.

The code that handles axe results in Lighthouse shows these "incomplete" results as findings only for informative audits. The result is a warning that appears in the report but does not affect the score.

A score that does not drop is not a reason to ignore the warning. The report's description says that adding captions to a video makes it easier for users who are deaf or hard of hearing (users with hearing impairments) to access the content. In axe-core's rule metadata, the impact is critical, the highest of its four levels (minor, moderate, serious, critical).

Create a caption file and load it with track

Captions are written in WebVTT, a plain-text format. The file I used starts with WEBVTT, then a blank line, then pairs of a display time and text.

text
WEBVTT

00:00:00.000 --> 00:00:03.000
字幕の表示を確かめるための動画です。

00:00:03.000 --> 00:00:06.000
[ピーという音が続く]

Save this as captions.vtt and load it with <track>, as in the "Fixed" example above. According to the MDN description of the track element, the attributes do the following.

  • kind: the type of text track. To fix this warning, set it to captions.
  • src: the URL of the .vtt file. If the <video> has no crossorigin attribute, put the file on the same origin as the page.
  • srclang: the language of the captions (for example ja)
  • label: the name shown in the browser's caption menu
  • default: if nothing else is set, show these captions by default

In my test, I moved the video file into a separate <source> element. I opened the fixed page in the Chromium that ships with Playwright, muted the sound, played the video, and paused it after 2 seconds. The captions were displayed.

In the lower part of a test video showing colour bars, white text reads "This is a video to check that captions display." (the caption text is in Japanese). The playback bar shows 0:02 / 0:06, with the play button and the muted volume button visible
Video with captions loaded through a track with kind=captions

When I checked this page with Lighthouse, the score stayed at 100, and video-caption moved to "not applicable" (notApplicable in the JSON). Being in "not applicable" rather than "passed" is also how informative audits are handled.

subtitles does not clear the warning

I changed how the <track> was written and compared Lighthouse's results. The browser captions column comes from opening each page in Chromium and checking video.textTracks and the readyState of the <track>. The number in parentheses is the count of cues (caption segments) that loaded.

Contents of <video> Lighthouse Captions in browser
No <track> Flagged None
kind="captions" Not applicable Loaded (2 cues)
kind="subtitles" Flagged Loaded (2 cues)
No kind attribute Flagged Loaded as subtitles (2 cues)
kind="CAPTIONS" (uppercase) Not applicable Loaded as captions (2 cues)
kind="captions", but the src file is missing Not applicable Failed to load (readyState is 3, 0 cues)
kind="captions" <track> added by JavaScript Not applicable Loaded (2 cues)

With kind="subtitles", the browser shows captions just the same, yet Lighthouse still flags the video. axe-core only checks whether kind is captions. If kind is omitted, the browser treats the track as subtitles, and that is flagged too.

The MDN description of the track element distinguishes the two kinds. subtitles are for people who can hear the audio but do not understand the language, such as translated dialogue. captions are for people who cannot hear the audio, and include sound effects, music, and who is speaking, in addition to dialogue. Lines such as "[a beeping sound continues]" in the .vtt above are what captions is for. Do not just change kind to captions. Make the content meant for people who cannot hear the audio as well.

A <track> added with JavaScript was also "not applicable". If the script adds the <track> while the page loads, it is checked just as one written in the HTML source would be.

Warning

As the table shows, a <track> whose src file is missing also clears the Lighthouse warning. Lighthouse does not check the contents of the caption file or whether it loaded. After fixing the page, play the video and confirm that captions actually appear.

Videos without sound, and pages with several videos

A background-style video with autoplay muted loop was also flagged when it had no <track>. axe-core does not check whether the video has sound. It only checks for <track>. Whether a silent video needs captions is your decision.

When I put a caption-less video and a video with kind="captions" on the same page, the problem elements listed only the <video> without captions. On a page with several videos, add captions to each <video> that appears in this list. On a page with no videos, this audit is "not applicable".

​Posted by 86