HTML <audio> hidden Attribute

The hidden attribute on an <audio> tag hides the audio element. Althought the audio element is not visible, its position on the page is maintained.

Example

#

A hidden attribute on an <audio> tag.
The audio player is not visible.

An invisible audio player:

<p>An invisible audio player:</p>

<audio hidden>
  <source src="/media/epic.mp3" type="audio/mpeg">
  <source src="/media/epic.wav" type="audio/wav">
</audio>

Using hidden

The hidden attribute hides the <audio> element.

You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid.

A hidden <audio> element is not visible, but it maintains its position on the page.

Removing the hidden attribute makes it re-appear.


Syntax

<a hidden>
or
<a hidden="hidden">

Values

#

Value Description
hidden Use 'hidden' or hidden='hidden'. Both are valid.

More Examples

Clicking the button toggles the hidden attribute on the <audio> player.



<audio id="myaudio" controls>
  <source src="/media/epic.mp3" type="audio/mpeg">
  <source src="/media/epic.wav" type="audio/wav">
</audio>

<br /><br />
<button onclick="toggle(this);">Hide Audio</button>

<script>
  let toggle = button => {
     let element = document.getElementById("myaudio");
     let hidden = element.getAttribute("hidden");

     if (hidden) {
        element.removeAttribute("hidden");
        button.innerText = "Hide Audio";
     } else {
        element.setAttribute("hidden", "hidden");
        button.innerText = "Show Audio";
     }
  }
</script>

Code explanation

Clicking the button invokes a JavaScript function that adds or removes the hidden attribute.

With the hidden attribute the <audio> element is invisible.


Browser support

Here is when hidden support started for each browser:

Chrome
4.0 Jan 2010
Firefox
3.5 Jun 2009
IE/Edge
9.0 Sep 2012
Opera
10.0 Aug 2009
Safari
11.5 Jun 2009

You may also like

 Back to <audio>
Guides