HTMLElement: hidden property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
TheHTMLElement propertyhidden reflects the value of the element'shidden attribute.
In this article
Value
This attribute may have one of three values:
trueThe element is hidden.
falseThe element is not hidden. This is the default value for the attribute.
"until-found"The element ishidden until found, meaning that it is hidden but will be revealed if found through in page search or reached through fragment navigation.
For details on the usage of this attribute, see the page for thehidden HTML attribute that this property reflects.
Examples
Here's an example where a hidden block is used to contain a 'thank you' message that isdisplayed after a user agrees to an unusual request.
HTML
The HTML contains two panels: a welcome panel, that asks users to agree to be awesome, and a follow-up panel, which is initially hidden.
<div> <h1>Welcome to my website!</h1> <p>By clicking "OK" you agree to be awesome today!</p> <button>OK</button></div><div hidden> <h1>Thanks!</h1> <p>Thanks for agreeing to be awesome today!</p></div>CSS
The content is styled using the CSS below.
.panel { font: 16px "Open Sans", "Helvetica", "Arial", sans-serif; border: 1px solid #2222dd; padding: 12px; width: 500px; text-align: center;}.button { font: 22px "Open Sans", "Helvetica", "Arial", sans-serif; padding: 5px 36px;}h1 { margin-top: 0; font-size: 175%;}JavaScript
The JavaScript adds an event listener to the "OK" button, which hides the "welcome" panel and shows the "awesome" panel:
document.getElementById("okButton").addEventListener("click", () => { document.getElementById("welcome").hidden = true; document.getElementById("awesome").hidden = false;});Result
Specifications
| Specification |
|---|
| HTML> # dom-hidden> |