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

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.
Presence = on.
FAQ panels.
Click to toggle.
Modals.
JS property.
React to changes.
open AttributeThe 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.
open is for details and dialog. Checkboxes use checked, not open. To react when open changes, use the toggle event (ontoggle).
Add the boolean open attribute to details or dialog:
<details open>
<summary>FAQ question</summary>
<p>Answer visible on load.</p>
</details>
<details>
<summary>Another question</summary>
<p>Collapsed by default.</p>
</details><details> and <dialog>.open="false" — any value still opens the element in HTML.<summary> as the first child of <details>.element.open = true or false.dialog.showModal() over only open.open fires the toggle event on details / dialog.The open attribute is a boolean attribute — it has no meaningful value string:
details or dialog is open when the page loads.<!-- Open by default -->
<details open>…</details>
<!-- Closed by default (omit open) -->
<details>…</details>
<!-- Wrong: still open in HTML -->
<details open="false">…</details>| Use case | Markup | Notes |
|---|---|---|
| FAQ open by default | <details open> | First answer visible |
| FAQ collapsed | <details> | Omit open |
| Open in JS | details.open = true | Current state |
| Close in JS | details.open = false | Preferred over removeAttribute alone |
| Modal dialog | dialog.showModal() | Backdrop + focus trap |
| React to change | ontoggle / toggle event | Fires when open toggles |
| Element | Supported? | Notes |
|---|---|---|
<details> | Yes | Primary use — FAQ / accordion |
<dialog> | Yes | Visible dialog; use showModal() for modals |
<summary> | Related | Child of details — click target |
<input type="checkbox"> | No | Use checked instead |
<div>, <section> | No | Not valid targets |
open vs ontoggle vs hidden| API | What it does | Typical use |
|---|---|---|
open | Initial / current open state | FAQ expanded by default |
ontoggle | JS when open changes | Track expand/collapse |
hidden | Hide any element | Generic visibility, not disclosure |
showModal() | Open modal dialog | Popups with backdrop |
Open vs closed details, dynamic .open in JavaScript, and a button that expands all FAQ items.
First panel has open; second is collapsed by default:
A boolean attribute that expands details on page load.
details and dialog — click to reveal this answer.
Compare an expanded FAQ panel with a collapsed one:
<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>The first <details> has open, so its content shows on load. The second omits open and stays collapsed until the user clicks <summary>.
Set details.open programmatically after the page loads:
<details id="dynamicDetails">
<summary>Click to toggle</summary>
<p>Opened by JavaScript on load.</p>
</details>
<script>
document.getElementById("dynamicDetails").open = true;
</script>The open property reflects and controls the current state. Setting it to true expands the widget; false collapses it.
Toggle every details element with buttons that set .open:
function setAllOpen(isOpen) {
document.querySelectorAll("details.faq").forEach(function (panel) {
panel.open = isOpen;
});
status.textContent = isOpen ? "All panels expanded" : "All panels collapsed";
}Loop over matching details elements and assign .open. Each change fires a toggle event if you need to listen with ontoggle.
<summary> as the clickable label for <details>.<summary> is focusable and activatable with Enter/Space by default.showModal() for modals so focus is trapped and Escape closes the dialog.details.Boolean on details/dialog.
Expanded on load.
Click summary.
No JS required.
The open attribute on <details> is universally supported in all modern browsers. On <dialog>, support follows the native dialog element.
open on detailsNative accordion behavior without JavaScript in every browser.
details 99% supportedBottom line: Safe for FAQ and accordion UI in all modern browsers.
open on details when one FAQ should show by default<summary> headingdetails.open = true/false in JavaScriptshowModal() for accessible modal dialogstoggle if you need to track state changesopen="false" — it still opens the elementopen on checkboxes or generic divsopen on a long pageopen with hidden or display:nonedetails is enoughThe 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.
openBookmark these before building FAQ sections.
Presence = open.
SyntaxFAQ UI.
ElementClick label.
ChildJS property.
APIWrong element.
Gotchadetails 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.details.open = true to expand, or details.open = false to collapse. This updates the current state and fires a toggle event.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.details in all modern browsers. dialog support follows native dialog element availability.Practice the open attribute on details with static HTML and dynamic JavaScript in the Try It editor.
5 people found this page helpful