Skip to main content
← πŸ“„ HTML & the platformΒ·Module A2 Β· Lesson 9
TaskBuild an FAQ with two details elements. Each has a <summary> question and a <p> answer. Questions: 'Is it free?' / 'Yes, the first 15 lessons.' and 'Need to install Python?' / 'No β€” runs in your browser.'

<details> and <summary>: native collapsibles

75 XP6 min
Theory

Browsers ship a free accordion widget

<details>
  <summary>Click to expand</summary>
  <p>Hidden content. Toggles on click. Keyboard-accessible.</p>
</details>

That's the entire feature. No JS. No framework. No event listeners. Works on every browser.

Open by default

<details open>
  <summary>This starts expanded</summary>
  <p>…</p>
</details>

Common uses

  • FAQ entries β€” clean, accessible, semantic.
  • "Show more" buttons β€” for long content sections.
  • Code-listing toggles β€” collapse the boilerplate.
  • Disclaimer / Terms β€” collapsed by default.

Style the marker

The default disclosure triangle is browser-specific (β–Ά β†’ β–Ό on most). Hide and replace:

summary {
  list-style: none;       /* Firefox + Chrome */
  cursor: pointer;
}
summary::-webkit-details-marker { display: none; }   /* Safari */
summary::before { content: "+"; margin-right: 8px; }
details[open] summary::before { content: "βˆ’"; }

NOT a modal

<details> collapses inline. For a modal that overlays the page, use <dialog> (next lesson) β€” different tag for a different job.

πŸ”’

Sign up to start coding

Theory is open to everyone. The interactive editor, live preview, and check are unlocked with a 7-day free trial β€” card required, cancel anytime.

Sign up β€” free trial β†’

First 15 lessons in each track are free. No card needed for those.

← PreviousNext lesson β†’

Get one Python or web tip a day β€” by email

Short, hand-written, no spam. Unsubscribe in one click.