HTML hidden Attribute

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 3 Examples
Visibility & Global Attributes

What You’ll Learn

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.

01

Boolean Global

Presence means hidden.

02

No Value Needed

hidden or hidden="".

03

Not type=hidden

Different from form input.

04

vs display:none

Semantic HTML choice.

05

element.hidden

Toggle with JavaScript.

06

Accessibility

Remove to reveal to AT.

Purpose of hidden Attribute

The 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.

💡
Not the same as <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.

📝 Syntax

Add hidden to any element where content should not be displayed:

hidden.html
<!-- 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>

Syntax Rules

  • hidden is a boolean global attribute—valid on nearly all HTML elements.
  • Presence means hidden; no value is required. Use hidden or hidden="".
  • hidden="false" does not show the element—boolean attributes are presence-based. Remove the attribute to show content.
  • To show hidden content with JavaScript, set element.hidden = false or call removeAttribute("hidden").
  • Do not confuse with <input type="hidden">, which is a form data control, not a visibility attribute.
  • Prefer removing hidden when content becomes relevant rather than overriding with CSS alone.

💎 Values

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.
  • Attribute absent — Element is visible (unless other CSS or attributes hide it).
  • hidden="false"Still hidden. The attribute is present, so the element remains hidden. Remove the attribute or use JavaScript to show it.
hidden-values.html
<!-- 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>

⚡ Quick Reference

ConceptDetailsNotes
Attribute typeBoolean globalValid on nearly all elements
Hide elementhidden or hidden=""Presence-based, not value-based
Show elementRemove attributeOr element.hidden = false
JS hideel.hidden = trueOr setAttribute("hidden", "")
JS showel.hidden = falseOr removeAttribute("hidden")
Not the same as<input type="hidden">Form data control, not visibility

Applicable Elements

ElementSupported?Notes
<div>, <section>, <p>YesGlobal attribute—common for panels and messages
<button>, <a>YesHide controls until needed
<form>, fieldsets, labelsYesOptional form sections
<table>, rows, cellsYesHide rows or columns conditionally
<input type="hidden">N/AUses type="hidden", not the hidden attribute
Any HTML elementYesGlobal attribute per HTML specification

hidden vs type="hidden" vs CSS display:none vs aria-hidden

ApproachExampleWhen to Use
hidden attribute<div hidden>Panel</div>Semantic HTML when content is not currently relevant; toggle with JS
type="hidden" input<input type="hidden" name="token">Submit form data invisibly—not for hiding arbitrary content
CSS display: none.panel { display: none; }Visual styling; no semantic signal that content is inactive
aria-hidden="true"<span aria-hidden="true">★</span>Hide decorative content from assistive tech while keeping it visible on screen
Show hidden contentRemove hidden or el.hidden = falseRestores visibility and accessibility tree exposure
Best practicehidden + remove when relevantPrefer semantic attribute over CSS-only hiding for inactive UI

Examples Gallery

Basic hidden markup, toggling visibility with JavaScript, and revealing optional form fields with a checkbox.

👀 Live Preview

A visible paragraph and a <div hidden> with a paragraph inside:

This paragraph is visible.

The yellow block is in the DOM but not displayed. Remove hidden to show it.

Example — Basic Hidden Content

Keep content in the DOM but out of view with the boolean hidden attribute:

basic-hidden.html
<p>This paragraph is visible.</p>

<div hidden>
  <p>This block is hidden by default because of the <code>hidden</code> attribute.</p>
</div>
Try It Yourself

How It Works

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.

Example — Toggle Visibility with JavaScript

Use the hidden IDL property to show or hide content in response to user interaction:

toggle-hidden.html
<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>
Try It Yourself

How It Works

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.

Example — Optional Form Section

Hide optional fields until the user opts in with a checkbox:

form-hidden.html
<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>
Try It Yourself

How It Works

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.

♿ Accessibility

  • Hidden content is not accessible while hidden — When 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.
  • Remove 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.
  • Do not use 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.
  • Prefer semantic hidden over CSS-only hiding — Signals that content is inactive, not merely styled away.
  • Test with keyboard and screen reader — Verify that toggling visibility updates what users can tab to and hear announced.

🧠 How hidden Works

1

Author adds hidden attribute

Boolean presence on any element.

Markup
2

Browser applies UA styles

Maps to display:none behavior.

Render
3

Element removed from a11y tree

Not shown or announced while hidden.

Platform
=

Content hidden until needed

Remove attribute or use JS to reveal.

Browser Support

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.

HTML5 · Fully supported

Universal visibility control

All major browsers honor the hidden global attribute and expose the hidden IDL property.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
hidden attribute 99% supported

Bottom line: Use hidden confidently for semantic visibility; toggle with element.hidden in JavaScript.

💡 Best Practices

✅ Do

  • Use hidden for content that is not currently relevant
  • Remove hidden (or set hidden = false) when showing content
  • Toggle with element.hidden in JavaScript
  • Distinguish from <input type="hidden"> for form data
  • Test keyboard focus after revealing hidden panels

❌ Don’t

  • Write hidden="false" expecting the element to show
  • Confuse the attribute with type="hidden" form inputs
  • Assume hidden content stays accessible to screen readers
  • Hide required form fields users must complete
  • Rely on CSS display:none alone when semantic hiding is clearer

Conclusion

The 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.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about hidden

Bookmark these before hiding your next UI panel.

5
Core concepts
🚫 02

Not false

hidden="false" hides.

Gotcha
📝 03

Not type=hidden

Form control only.

Compare
⚙️ 04

element.hidden

Toggle in JS.

Script
05

Remove to reveal

Restore a11y access.

A11y

❓ Frequently Asked Questions

It is a boolean global attribute. When present, the browser hides the element from view using user agent styles (effectively display: none). The element stays in the DOM but is not shown to users or assistive technology while hidden.
No. The 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.
No. Boolean attributes are presence-based. If 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.
Both hide content visually. 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.
Use element.hidden = true or element.hidden = false. You can also call element.removeAttribute("hidden") to show content or element.setAttribute("hidden", "") to hide it.
Yes. All modern browsers support the hidden global attribute and the element.hidden property. Use add and remove patterns for reliable cross-browser behavior.

Hide and reveal content the right way

Practice the hidden attribute with basic, toggle, and form examples in the Try It editor.

Try basic hidden example →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

4 people found this page helpful