HTML open Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The open attribute is a Boolean on <details> and <dialog>. When present, a disclosure starts expanded, or a dialog is shown (as a non-modal dialog). When absent, details start closed and the dialog is not displayed.

Pair details with <summary> for the label. Users can still toggle details; the attribute only sets the initial (and current) open state.

Baseline · Widely available (details).

Not deprecated. Boolean: presence means on. Write open, not open="false".

Dialog: prefer show() / showModal().

MDN recommends opening dialogs with JavaScript methods. Markup <dialog open> is non-modal and already visible on load — fine for demos, not the best pattern for interactive modals.

HTML Syntax

syntax.html
<details open>  … </details>
<dialog open>  … </dialog>

In JavaScript: element.open = true or false reflects the attribute on both elements.

Attribute Values

Boolean — no value list. Behavior by element:

ElementWith openTry it
<details>Contents visible; user can still toggleTry it
<details> (no open)Starts collapsedTry it
<dialog open>Non-modal dialog visible on loadTry it

Live Preview

Toggle the disclosure. The log reflects the live open state (details.open).

details

Buttons add or remove the Boolean attribute. Click the summary to toggle by hand too.

System requirements

A computer, some memory, and an input device are recommended.

State

open: true

HTML Examples

Short demos for details and dialog. Use Try It Yourself for a live editor.

Example 1 — Start <details> Expanded

Add the Boolean open attribute so content is visible on load.

HTML
<details open>
  <summary>System Requirements</summary>
  <p>Requires memory, storage, and an input device.</p>
</details>
Try It Yourself

How It Works

  1. open is present on <details>.
  2. summary stays visible as the control label.
  3. Body content is shown immediately.
  4. User can still click summary to collapse.

Example 2 — Closed by Default + Read .open

Omit open, then watch the toggle event update a status line.

HTML
<p id="state">open: false</p>
<details id="d">
  <summary>More info</summary>
  <p>Hidden until you open the disclosure.</p>
</details>
<script>
  var d = document.getElementById("d");
  d.addEventListener("toggle", function () {
    document.getElementById("state").textContent =
      "open: " + d.open;
  });
</script>
Try It Yourself

How It Works

  1. No open attribute — starts collapsed.
  2. User toggles the summary.
  3. toggle fires after the state changes.
  4. details.open mirrors the Boolean attribute.

Example 3 — Non-modal <dialog open>

Markup-only open dialog (non-modal). Prefer showModal() for real modals.

HTML
<dialog open>
  <p>Greetings — this dialog loaded already open.</p>
  <form method="dialog">
    <button>OK</button>
  </form>
</dialog>
Try It Yourself

How It Works

  1. open on <dialog> shows it as non-modal.
  2. Page loads with the dialog already visible.
  3. method="dialog" on the form closes it when submitted.
  4. For modals use dialog.showModal() instead of the attribute.

Edge Cases & Pitfalls

Boolean rules and dialog modality cause most confusion.

boolean

open="false" still opens

Remove the attribute (or set .open = false) to close.

dialog

Attribute open ≠ modal

<dialog open> is non-modal. Use showModal() for a true modal with backdrop and Esc dismiss.

summary

Always include <summary>

Without it, the UA may invent a default label. Put a clear summary first inside details.

name

Grouped details: only one open

Same name on several details makes an accordion. If several have open, only the first in source order stays open.

style

Style open state with [open] or :open

details[open] (and :open where supported) targets the expanded widget.

Browser Support

open is an HTML Boolean attribute on details and dialog. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

open

Supported on modern browsers for details disclosures and dialog. Prefer showModal() for interactive modal dialogs.

96% Global support (approx.)
Google Chrome Yes
Full support
Mozilla Firefox Yes
Full support
Apple Safari Yes
Full support
Microsoft Edge Yes
Full support
Opera Yes
Full support
Samsung Internet Yes
Full support
Internet Explorer No
Not supported
open Widely supported

Bottom line: Safe to use for details. For dialogs, learn the attribute, then prefer show() / showModal() in real UIs.

Key Takeaways

  • Boolean on details and dialog.
  • Presence = open; omit to start closed / hidden.
  • details.open reflects state; listen for toggle.
  • Dialogs: prefer showModal() over the attribute.

One line: open is the Boolean that starts a disclosure expanded or shows a non-modal dialog.

Frequently Asked Questions

It is a Boolean attribute on <details> and <dialog>. When present, details content is visible, or a dialog is shown as a non-modal dialog. When absent, details start closed and a dialog is not displayed.
No. Boolean attributes are on when present. open="false" still means open. Remove the attribute entirely to close.
MDN recommends show() or showModal() instead of the open attribute. Markup with open creates a non-modal dialog already visible on load; modal dialogs need showModal().
Set details.open = true or element.setAttribute("open", ""). Set details.open = false or removeAttribute("open") to close. Listen for the toggle event after the state changes.
No. It is standard on details and dialog. Prefer dialog methods for interactive dialogs.
Yes. The name attribute on details groups them so only one in the group can be open at a time (accordion-style), independent of the open attribute itself.

Next: optimum

Mark the preferred value on a meter element.

optimum tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

8 people found this page helpful