A hidden attribute on an <iframe> tag hides the iframe.
Although the iframe is not visible, its position on the page is maintained.
A hidden attribute on an <iframe>.
The iframe is not visible.
A hidden iframe:
<p>A hidden iframe:</p>
<iframe src="https://en.wikipedia.org" style="width:100%;" hidden>
</iframe>
The hidden attribute hides the <iframe> element.
You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid.
A hidden <iframe> is not visible, but maintains its position on the page.
<iframe hidden>
<iframe hidden="hidden">
Value | Description |
---|---|
hidden | Use value 'hidden' or no value at all. |
Clicking the button toggles A hidden attribute on the <iframe> element.
<iframe id="myiframe" src="https://en.wikipedia.org" style="height:450px;width:100%;"></iframe>
<br /><br />
<button onclick="toggle(this);">Hide Iframe</button>
<script>
let toggle = button => {
let element = document.getElementById("myiframe");
let hidden = element.getAttribute("hidden");
if (hidden) {
element.removeAttribute("hidden");
button.innerText = "Hide Iframe";
} else {
element.setAttribute("hidden", "hidden");
button.innerText = "Show Iframe";
}
}
</script>
Initially, the <iframe> element has no hidden attribute and is visible.
Clicking the button calls JavaScript that toggles A hidden attribute on the <iframe>.
Here is when hidden support started for each browser:
Chrome
|
1.0 | Sep 2008 |
Firefox
|
1.0 | Sep 2002 |
IE/Edge
|
1.0 | Aug 1995 |
Opera
|
1.0 | Jan 2006 |
Safari
|
1.0 | Jan 2003 |