HTML <img> hidden Attribute

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

Example

#

A hidden attribute on an <img>.
The image is not visible.

A hidden image:

<p>A hidden image:</p>

<img src="/img/html/parliament.jpg" hidden>

Using hidden

The hidden attribute hides the <img> element.

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

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


Syntax

<img hidden>
or
<img hidden="hidden">

Values

#

Value Description
hidden Use value 'hidden' or no value at all.

More Examples

Clicking the button toggles the hidden attribute on the <img> element.



<img id="myimg" src="/img/html/parliament.jpg">

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

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

Code explanation

Initially, the <img> element has no hidden attribute and can be seen.

Repeatedly clicking the button calls JavaScript that toggles the hidden attribute from the <img> element.

The hidden attribute hides the image.


Browser support

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

You may also like

 Back to <img>
Guides