Details and Summary Disclosure

Uses native details and summary elements to create accessible expandable content sections without JavaScript, with custom styling.

HtmlForm Validation

Code

snippet
<details>
  <summary>Click to expand</summary>
  <p>This content is hidden by default and shown when the summary is clicked.</p>
</details>

<details open>
  <summary>FAQ: What is HTML?</summary>
  <p>HTML (HyperText Markup Language) is the standard markup language for web pages.</p>
</details>

<details>
  <summary>Settings</summary>
  <form>
    <label>
      <input type="checkbox" name="notifications" checked>
      Enable notifications
    </label>
    <label>
      <input type="checkbox" name="auto-save">
      Auto-save changes
    </label>
    <button type="submit">Save Settings</button>
  </form>
</details>

<details>
  <summary>Code Example</summary>
  <pre><code>function greet(name) {
  return `Hello, ${name}!`;
}</code></pre>
</details>

<style>
  summary {
    cursor: pointer;
    padding: 0.5rem;
    font-weight: bold;
    list-style: none;
  }
  summary::-webkit-details-marker {
    display: none;
  }
  details[open] > summary {
    border-bottom: 1px solid #ccc;
  }
</style>

What the code does

The markup uses the semantic elements details and summary instead of generic containers, giving assistive technology and search engines real structure without extra wiring.

<details>/<summary> provide a native disclosure widget that works without JavaScript.

The form collects input via type="checkbox", type="submit" fields, each tied to a <label> so every control announces what it is.

Statements that matter

<summary>Click to expand</summary>
<p>This content is hidden by default and shown when the summary is clicked.</p>
<details open>

Interactive Tools for This Topic

FAQ

Why semantic elements instead of divs?
`<details>`, `<summary>` expose document structure to assistive technology and search engines without ARIA or class-name conventions.