HTML open Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Boolean & State

Introduction

The open attribute is a boolean attribute used on <details> and <dialog> elements to control whether the widget is expanded or visible when the page loads. On <details>, add open to show the hidden content by default — perfect for FAQ sections where the first answer should be visible. On <dialog>, open makes the dialog appear (for modals, prefer showModal() in JavaScript). Users can still toggle <details> by clicking <summary>. Read and set element.open in JavaScript to change state programmatically.

What You’ll Learn

01

Boolean

Presence = on.

02

details

FAQ panels.

03

summary

Click to toggle.

04

dialog

Modals.

05

.open

JS property.

06

ontoggle

React to changes.

Purpose of open Attribute

The primary purpose of open is to set the initial visibility of a disclosure widget. Without open, a <details> element is collapsed when the page loads. With open, its content is expanded immediately — useful when the information is important enough to show without an extra click.

On <dialog>, open indicates the dialog is shown. For modal dialogs with backdrop and focus trapping, use dialog.showModal() in JavaScript instead of only the attribute. Pair <details> with <summary> for an accessible clickable heading.

💡
Not for checkboxes

open is for details and dialog. Checkboxes use checked, not open. To react when open changes, use the toggle event (ontoggle).

📝 Syntax

Add the boolean open attribute to details or dialog:

open.html
<details open>
  <summary>FAQ question</summary>
  <p>Answer visible on load.</p>
</details>

<details>
  <summary>Another question</summary>
  <p>Collapsed by default.</p>
</details>

Syntax Rules

  • Boolean attribute — presence means open; omit for closed/collapsed.
  • Valid on <details> and <dialog>.
  • Do not write open="false" — any value still opens the element in HTML.
  • Always include <summary> as the first child of <details>.
  • In JavaScript, use element.open = true or false.
  • For modal dialogs, prefer dialog.showModal() over only open.
  • Changing open fires the toggle event on details / dialog.

💎 Values

The open attribute is a boolean attribute — it has no meaningful value string:

  • Present — The details or dialog is open when the page loads.
  • Absent — The widget is collapsed or hidden by default.
open-boolean.html
<!-- Open by default -->
<details open></details>

<!-- Closed by default (omit open) -->
<details></details>

<!-- Wrong: still open in HTML -->
<details open="false"></details>

⚡ Quick Reference

Use caseMarkupNotes
FAQ open by default<details open>First answer visible
FAQ collapsed<details>Omit open
Open in JSdetails.open = trueCurrent state
Close in JSdetails.open = falsePreferred over removeAttribute alone
Modal dialogdialog.showModal()Backdrop + focus trap
React to changeontoggle / toggle eventFires when open toggles

Applicable Elements

ElementSupported?Notes
<details>YesPrimary use — FAQ / accordion
<dialog>YesVisible dialog; use showModal() for modals
<summary>RelatedChild of details — click target
<input type="checkbox">NoUse checked instead
<div>, <section>NoNot valid targets

open vs ontoggle vs hidden

APIWhat it doesTypical use
openInitial / current open stateFAQ expanded by default
ontoggleJS when open changesTrack expand/collapse
hiddenHide any elementGeneric visibility, not disclosure
showModal()Open modal dialogPopups with backdrop

Examples Gallery

Open vs closed details, dynamic .open in JavaScript, and a button that expands all FAQ items.

👀 Live Preview

First panel has open; second is collapsed by default:

What is the open attribute?

A boolean attribute that expands details on page load.

Which elements use open?

details and dialog — click to reveal this answer.

Example — details with and without open

Compare an expanded FAQ panel with a collapsed one:

details-open.html
<details open>
  <summary>Click to toggle</summary>
  <p>This content is visible by default.</p>
</details>

<details>
  <summary>Click to toggle</summary>
  <p>This content is initially hidden.</p>
</details>
Try It Yourself

How It Works

The first <details> has open, so its content shows on load. The second omits open and stays collapsed until the user clicks <summary>.

Dynamic Values with JavaScript

Set details.open programmatically after the page loads:

dynamic-open.html
<details id="dynamicDetails">
  <summary>Click to toggle</summary>
  <p>Opened by JavaScript on load.</p>
</details>

<script>
  document.getElementById("dynamicDetails").open = true;
</script>
Try It Yourself

How It Works

The open property reflects and controls the current state. Setting it to true expands the widget; false collapses it.

Example — Expand all FAQ panels

Toggle every details element with buttons that set .open:

expand-all-faq.html
function setAllOpen(isOpen) {
  document.querySelectorAll("details.faq").forEach(function (panel) {
    panel.open = isOpen;
  });
  status.textContent = isOpen ? "All panels expanded" : "All panels collapsed";
}
Try It Yourself

How It Works

Loop over matching details elements and assign .open. Each change fires a toggle event if you need to listen with ontoggle.

♿ Accessibility

  • Use summary — Always provide a descriptive <summary> as the clickable label for <details>.
  • Do not overuse open — Expanding many sections by default can overwhelm screen-reader users scanning the page.
  • Keyboard support<summary> is focusable and activatable with Enter/Space by default.
  • Dialog focus — Use showModal() for modals so focus is trapped and Escape closes the dialog.
  • State is announced — Assistive tech reports expanded/collapsed state on details.

🧠 How open Works

1

Author adds open

Boolean on details/dialog.

Markup
2

Content visible

Expanded on load.

Display
3

User toggles

Click summary.

Interaction
=

Disclosure widget

No JS required.

Browser Support

The open attribute on <details> is universally supported in all modern browsers. On <dialog>, support follows the native dialog element.

HTML5 Disclosure · Fully supported

Reliable open on details

Native accordion behavior without JavaScript in every browser.

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
Internet Explorer Not supported
Use polyfill
Opera Fully supported
Full support
open on details 99% supported

Bottom line: Safe for FAQ and accordion UI in all modern browsers.

💡 Best Practices

✅ Do

  • Use open on details when one FAQ should show by default
  • Always include a clear <summary> heading
  • Set details.open = true/false in JavaScript
  • Use showModal() for accessible modal dialogs
  • Listen for toggle if you need to track state changes

❌ Don’t

  • Write open="false" — it still opens the element
  • Put open on checkboxes or generic divs
  • Expand every FAQ with open on a long page
  • Confuse open with hidden or display:none
  • Rely on custom accordion JS when details is enough

Conclusion

The open attribute controls whether a details or dialog widget starts expanded or visible — a simple boolean that powers native FAQ accordions without extra CSS or JavaScript.

Omit open for collapsed panels, add it for visible-by-default content, and use element.open in script when you need dynamic control.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about open

Bookmark these before building FAQ sections.

5
Core concepts
📋 02

details

FAQ UI.

Element
💬 03

summary

Click label.

Child
04

.open

JS property.

API
05

Not checked

Wrong element.

Gotcha

❓ Frequently Asked Questions

It is a boolean attribute on details and dialog that makes the element expanded or visible when the page loads. Without it, details content is collapsed by default.
<details> and <dialog>. Pair details with <summary> for the clickable heading.
Set details.open = true to expand, or details.open = false to collapse. This updates the current state and fires a toggle event.
No. open is boolean — any presence means open. Omit the attribute entirely for a collapsed default state.
open on a dialog makes it visible. showModal() opens it as a modal with backdrop, focus trap, and Escape-to-close — preferred for popups.
Yes for details in all modern browsers. dialog support follows native dialog element availability.

Build FAQ accordions

Practice the open attribute on details with static HTML and dynamic JavaScript in the Try It editor.

Try open demo →

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.

5 people found this page helpful