<details>

The HTML <details> element generates a disclosure widget that allows users to access additional information or controls, featuring a toggle to expand or collapse the content.

<details> Tag

A disclosure widget typically features a rotating triangle to indicate its open or closed status, along with a label from the <summary> element. The <details> element provides an accessible description for the <summary>.

Syntax

index.html
<details>
  <summary>Summary or Heading</summary>
  Detailed information that is hidden until the user clicks to reveal it.
</details>

<details> Demo

Details Something small enough to escape casual notice.
index.html
<details>
  <summary>Details</summary>
  Something small enough to escape casual notice.
</details>
The <summary> tag serves as a clickable heading or label for the details section. The content inside the <details> tag is hidden by default and becomes visible when the user clicks the summary.

Attributes

This element includes the global attributes.

  • open
    A Boolean attribute that indicates whether the content of the <details> element is visible. It is displayed when present and hidden by default when absent.
  • name
    This attribute allows multiple <details> elements to be linked, ensuring that only one is open at a time. This feature facilitates the creation of UI elements like accordions without the need for scripting.

Conclusion

The <details> tag in HTML provides an interactive way to hide or reveal content, enhancing user experience. It works with the <summary> tag, which acts as a clickable heading for the hidden content. The open attribute controls whether the content is visible by default, and the name attribute helps link multiple <details> elements.