A hidden attribute on an <audio> tag hides the audio element.
Although the audio element is not visible, its position on the page is maintained.
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>
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.
<a hidden>
<a hidden="hidden">
Value | Description |
---|---|
hidden | Use 'hidden' or hidden='hidden'. Both are valid. |
Clicking the button toggles A 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>
Clicking the button invokes a JavaScript function that adds or removes the hidden attribute.
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 |