Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

HTML <object> hidden Attribute

A hidden attribute on an <object> tag hides the object.

Although the object is not visible, its position on the page is maintained.

Example

#

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

A hidden object:

<p>A hidden object:</p>

<object data="/media/sample.pdf" type="application/pdf"
        style="width:100%;height:350px;" hidden>
   PDF cannot be displayed.
</object>

Using hidden

The hidden attribute hides the <object> element.

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

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

Removing the hidden attribute makes it re-appear.


Syntax

<object hidden>
or
<object hidden="hidden">

Values

#

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

More Examples

Clicking the button toggles A hidden attribute on the <object> element.

PDF cannot be displayed.

<object id="myobject" data="/media/sample.pdf"
        type="application/pdf" style="width:100%;height:350px;">
   PDF cannot be displayed.
</object>

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

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

Code explanation

Initially the <object> is visible and does not have a hidden attribute.

Clicking the button calls JavaScript which toggles the hidden attribute.

With the hidden attribute the <object> is not visible.


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 <object>
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

Guides