👀 Live Preview
A visible paragraph and a <div hidden> with a paragraph inside:
This paragraph is visible.
This block is hidden because of the hidden attribute.
The yellow block is in the DOM but not displayed. Remove hidden to show it.

The hidden attribute is a boolean global attribute that hides an element from view. When present, the browser does not display the element—though it remains in the DOM. Use it for content that is not currently relevant, toggle it with JavaScript, and remove it when content should become visible and accessible again.
Presence means hidden.
hidden or hidden="".
Different from form input.
Semantic HTML choice.
Toggle with JavaScript.
Remove to reveal to AT.
hidden AttributeThe hidden attribute tells the browser that an element is not currently relevant and should not be shown. It is a boolean global attribute, which means it can appear on almost any HTML element. You do not need to assign a value—simply include hidden or hidden="" and the element is hidden.
Browsers hide elements with this attribute through user agent styles (effectively display: none). The content stays in the document tree, so you can reveal it later by removing the attribute or setting element.hidden = false in JavaScript. This makes hidden ideal for panels, optional form sections, and UI that appears only after user action.
<input type="hidden">The hidden attribute hides any element from display. <input type="hidden"> is a form control that submits data with a form while staying invisible. They are completely different features—do not confuse the attribute with the input type.
Add hidden to any element where content should not be displayed:
<!-- Boolean: presence hides the element -->
<p>This paragraph is visible.</p>
<div hidden>
<p>This block is hidden until you remove the attribute.</p>
</div>
<!-- Equivalent empty string value -->
<section hidden="">Not shown</section>
<!-- Wrong: hidden="false" STILL hides the element -->
<div hidden="false">Still hidden!</div>hidden is a boolean global attribute—valid on nearly all HTML elements.hidden or hidden="".hidden="false" does not show the element—boolean attributes are presence-based. Remove the attribute to show content.element.hidden = false or call removeAttribute("hidden").<input type="hidden">, which is a form data control, not a visibility attribute.hidden when content becomes relevant rather than overriding with CSS alone.As a boolean attribute, hidden has no meaningful value—only presence or absence matters:
hidden — Element is hidden. Most common form.hidden="" — Also hides the element. Empty string is equivalent to presence.hidden="false" — Still hidden. The attribute is present, so the element remains hidden. Remove the attribute or use JavaScript to show it.<!-- Hidden: attribute present -->
<div hidden>Not visible</div>
<!-- Visible: no hidden attribute -->
<div>Visible</div>
<!-- JavaScript: show and hide -->
<script>
var panel = document.getElementById("panel");
panel.hidden = true; // hide
panel.hidden = false; // show
panel.removeAttribute("hidden"); // show
panel.setAttribute("hidden", ""); // hide
</script>| Concept | Details | Notes |
|---|---|---|
| Attribute type | Boolean global | Valid on nearly all elements |
| Hide element | hidden or hidden="" | Presence-based, not value-based |
| Show element | Remove attribute | Or element.hidden = false |
| JS hide | el.hidden = true | Or setAttribute("hidden", "") |
| JS show | el.hidden = false | Or removeAttribute("hidden") |
| Not the same as | <input type="hidden"> | Form data control, not visibility |
| Element | Supported? | Notes |
|---|---|---|
<div>, <section>, <p> | Yes | Global attribute—common for panels and messages |
<button>, <a> | Yes | Hide controls until needed |
<form>, fieldsets, labels | Yes | Optional form sections |
<table>, rows, cells | Yes | Hide rows or columns conditionally |
<input type="hidden"> | N/A | Uses type="hidden", not the hidden attribute |
| Any HTML element | Yes | Global attribute per HTML specification |
Basic hidden markup, toggling visibility with JavaScript, and revealing optional form fields with a checkbox.
A visible paragraph and a <div hidden> with a paragraph inside:
This paragraph is visible.
This block is hidden because of the hidden attribute.
The yellow block is in the DOM but not displayed. Remove hidden to show it.
Keep content in the DOM but out of view with the boolean hidden attribute:
<p>This paragraph is visible.</p>
<div hidden>
<p>This block is hidden by default because of the <code>hidden</code> attribute.</p>
</div>The browser sees the hidden attribute and applies user agent styles that hide the element. No JavaScript is required. To show the block, remove hidden from the markup or set element.hidden = false.
Use the hidden IDL property to show or hide content in response to user interaction:
<button type="button" id="toggleBtn">Toggle visibility</button>
<div id="toggleElement">
<p>This panel can be shown or hidden with the button.</p>
</div>
<script>
document.getElementById("toggleBtn").addEventListener("click", function () {
var el = document.getElementById("toggleElement");
el.hidden = !el.hidden;
});
</script>Setting element.hidden = true adds the attribute and hides the element. Setting it to false removes the attribute and shows the element. The click handler uses addEventListener rather than inline onclick for cleaner separation of HTML and behavior.
Hide optional fields until the user opts in with a checkbox:
<form action="#">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<label>
<input type="checkbox" id="shipToggle">
Add shipping address
</label>
<div id="addressPanel" hidden>
<label for="street">Street:</label>
<input type="text" id="street" name="street">
</div>
</form>
<script>
var toggle = document.getElementById("shipToggle");
var panel = document.getElementById("addressPanel");
toggle.addEventListener("change", function () {
panel.hidden = !toggle.checked;
});
</script>The address panel starts with hidden, so it is not displayed or exposed to assistive technology. When the checkbox is checked, JavaScript sets panel.hidden = false, removing the attribute and revealing the fields for sighted users and screen readers alike.
hidden is present, content is not shown to users and is removed from the accessibility tree. Do not assume hidden content remains available to assistive technology.hidden when revealing content — To make content available again, remove the attribute or set element.hidden = false so screen readers and keyboard users can reach it.hidden on focusable controls users need — Hiding required form fields or primary actions blocks interaction entirely.aria-hidden is different — Use aria-hidden="true" to hide decorative visible content from assistive tech, not to hide content from everyone.hidden over CSS-only hiding — Signals that content is inactive, not merely styled away.Boolean presence on any element.
Maps to display:none behavior.
Not shown or announced while hidden.
Remove attribute or use JS to reveal.
The hidden attribute is fully supported in all modern browsers as a global HTML attribute. Use element.hidden or add and remove the attribute for consistent behavior across Chrome, Firefox, Safari, and Edge.
All major browsers honor the hidden global attribute and expose the hidden IDL property.
Bottom line: Use hidden confidently for semantic visibility; toggle with element.hidden in JavaScript.
hidden for content that is not currently relevanthidden (or set hidden = false) when showing contentelement.hidden in JavaScript<input type="hidden"> for form datahidden="false" expecting the element to showtype="hidden" form inputsdisplay:none alone when semantic hiding is clearerThe hidden attribute is a simple, semantic way to hide HTML elements. As a boolean global attribute, its presence is all that matters—no value required. Remember that hidden="false" still hides the element, and that this feature is entirely separate from <input type="hidden">.
Toggle visibility with element.hidden, removeAttribute("hidden"), or setAttribute("hidden", ""). When content becomes relevant, remove the attribute so users and assistive technology can access it. For decorative visible-only content, use aria-hidden instead.
hiddenBookmark these before hiding your next UI panel.
Presence = hidden.
Syntaxhidden="false" hides.
GotchaForm control only.
CompareToggle in JS.
ScriptRestore a11y access.
A11ydisplay: none). The element stays in the DOM but is not shown to users or assistive technology while hidden.hidden attribute hides any HTML element from display. <input type="hidden"> is a form control that submits data with a form while staying invisible. They are completely different features.hidden is on the element, it is hidden regardless of the value. Remove the attribute or set element.hidden = false in JavaScript to show it.hidden is semantic HTML that signals content is not currently relevant. Browsers map it to display: none via user agent styles. Prefer removing hidden when content becomes relevant rather than overriding with CSS alone.element.hidden = true or element.hidden = false. You can also call element.removeAttribute("hidden") to show content or element.setAttribute("hidden", "") to hide it.hidden global attribute and the element.hidden property. Use add and remove patterns for reliable cross-browser behavior.Practice the hidden attribute with basic, toggle, and form examples in the Try It editor.
4 people found this page helpful