Disclosure lifecycle

Read on demand. Sync when visible.

Use <details> when people should choose whether to read a transcript. The enhancement is active only while the content is visible.

Native first

  • The transcript remains readable without JavaScript.
  • No transcript logic runs while the disclosure is closed.
  • Opening the disclosure initializes or reinitializes media sync.

Scenario

An episode page keeps its transcript available on demand. The native disclosure works without JavaScript; JavaScript only adds media sync and cue seeking while open.

Try it

Example

Read the transcript

Transcript — Local narration

Developer notes

Keep a reference to the returned instance. On close, call destroy(); it removes media, cue, document, and generated-status listeners and markup. On the next open, call init() to bind the visible transcript again.

let transcript = null;

function updateTranscript() {
  if (disclosure.open) {
    if (transcript) transcript.init();
    else transcript = createA11yTranscript(root);
    return;
  }

  transcript?.destroy();
}

disclosure.addEventListener("toggle", updateTranscript);
updateTranscript();

Accessibility notes