Codectionary / Developer documentation / HTML

<details>, <summary>

The <details> element creates a native, collapsible disclosure widget — content that can be toggled open or closed by the user without any JavaScript. The <summary> element inside it defines the always-visible heading that acts as the toggle control. This is the standard way to build FAQ accordions or collapsible sections without hand-rolling the interaction logic.

Syntax

<details>
  <summary>Click to expand</summary>
  <p>Hidden content</p>
</details>

Examples

Basic Collapsible Section

A simple expandable/collapsible content block.

<details>
  <summary>What is HTML?</summary>
  <p>HTML is the standard markup language for creating web pages.</p>
</details>

FAQ Accordion

Multiple details elements used to build an FAQ section.

<details>
  <summary>Is Codectionary free?</summary>
  <p>Yes, all core learning content is free.</p>
</details>
<details>
  <summary>Do I need an account?</summary>
  <p>An account is needed to save progress and take quizzes.</p>
</details>

Open by Default

Using the open attribute so the content starts expanded.

<details open>
  <summary>Important Notice</summary>
  <p>This section is expanded by default when the page loads.</p>
</details>

Attributes

  • open (boolean): Shows the details content expanded by default

Best practices

  • Use <details>/<summary> for simple show/hide UI instead of building the same thing manually with JavaScript and ARIA attributes
  • Always include a <summary> — without one, browsers show a generic default label
  • Style the disclosure triangle with the ::marker pseudo-element rather than hiding it and building a custom one, when possible
  • Great fit for FAQs, changelogs, and "read more" sections

At a glance

Purpose
Structure and meaning for web content
File extension
.html · .htm
Runs in
Web browsers
Usually used with
CSS and JavaScript

Specifications & further reading

Related HTML documentation