HTML <picture> hidden Attribute

The hidden attribute on a <picture> tag hides that picture. Althought the picture is not visible, its position on the page is maintained.

Example

#

A hidden attribute on a <picture> tag.
The picture is not visible.

A hidden picture element:

<p>A hidden picture element:</p>

<picture hidden>
  <source media="(max-width: 520px)" srcset="/img/html/vangogh-sm.jpg">
  <source media="(max-width: 768px)" srcset="/img/html/vangogh.jpg">
  <img src="/img/html/vangogh-lg.jpg" alt="Vincent Van Gogh">
</picture>

Using hidden

The hidden attribute hides the <picture> element.

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

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

Removing the hidden attribute makes it re-appear.


Syntax

<picture hidden>
or
<picture 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 <picture> element.

Vincent Van Gogh

<picture id="mypicture">
  <source media="(max-width: 520px)" srcset="/img/html/vangogh-sm.jpg">
  <source media="(max-width: 768px)" srcset="/img/html/vangogh.jpg">
  <img src="/img/html/vangogh-lg.jpg" alt="Vincent Van Gogh">
</picture>

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

<script>
  let toggle = button => {
    let element = document.getElementById("mypicture");
    let hidden = element.getAttribute("hidden");
    
    if (hidden) {
       element.removeAttribute("hidden");
       button.innerText = "Hide picture";
    } else {
       element.setAttribute("hidden", "hidden");
       button.innerText = "Show picture";
    }
  }
</script>

Code explanation

Initially, the <picture> is visible.

Clicking the button calls JavaScript which toggles the hidden attribute.

With the hidden attribute the picture is invisible.


Browser support

Here is when hidden support started for each browser:

Chrome
38.0 Oct 2014
Firefox
38.0 May 2015
IE/Edge
13.0 Nov 2015
Opera
25.0 Oct 2014
Safari
9.1 Mar 2016

You may also like

 Back to <picture>
Guides