Intended usage
The intended usage for hidden
(and also explicitly when not to use it) is explained on the page you linked:
The hidden
global attribute is a Boolean
attribute indicating that the element is not yet, or is no longer, relevant. For example, it can be used to hide elements of the page that can't be used until the login process has been completed.
The hidden
attribute must not be used to hide content that could legitimately be shown in another presentation. For example, it is incorrect to use hidden to hide panels in a tabbed dialog, because the tabbed interface is merely a kind of overflow presentation — one could equally well just show all the form controls in one big page with a scrollbar. It is similarly incorrect to use this attribute to hide content just from one presentation — if something is marked hidden, it is hidden from all presentations, including, for instance, screen readers.
Normal display:
.box {
background-color: #f0f0f0;
padding: 50px;
}
.inner {
background-color: #ccc;
height: 200px;
}
<div class="box">
<div class="inner"></div>
</div>
[hidden]
.box {
background-color: #f0f0f0;
padding: 50px;
}
.inner {
background-color: #ccc;
height: 200px;
}
<div class="box">
<div class="inner" hidden></div>
</div>
visibility: hidden;
.box {
background-color: #f0f0f0;
padding: 50px;
}
.inner {
background-color: #ccc;
height: 200px;
visibility: hidden;
}
<div class="box">
<div class="inner"></div>
</div>
display: none;
.box {
background-color: #f0f0f0;
padding: 50px;
}
.inner {
background-color: #ccc;
display: none;
height: 200px;
}
<div class="box">
<div class="inner"></div>
</div>
Using HTMLElement.prototype.hidden
property:
document.querySelector('.inner').hidden = true;
.box {
background-color: #f0f0f0;
padding: 50px;
}
.inner {
background-color: #ccc;
height: 200px;
}
<div class="box">
<div class="inner"></div>
</div>