October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

Pure CSS Accordion: Build One with HTML and CSS

Use native HTML details and summary elements to build a CSS-styled accordion without JavaScript, with optional one-at-a-time behavior.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a simple accordion that opens and closes without JavaScript, use HTML’s native <details> and <summary> elements, then style them with CSS. The browser manages each panel’s state; you can choose whether several panels may stay open or whether opening one closes the others.

Build a basic CSS-only accordion

Place each disclosure in a <details> element and make its first child a concise <summary> label. Content after the summary is the panel. This example lets visitors open multiple answers at once:

As an Amazon Associate I earn from qualifying purchases.

<div class="accordion">
  <details>
    <summary>What is a pure CSS accordion?</summary>
    <p>A group of collapsible content panels styled with CSS.</p>
  </details>
  <details>
    <summary>Does it require JavaScript?</summary>
    <p>This native disclosure version does not require JavaScript for toggling.</p>
  </details>
</div>
.accordion details {
  border-block: 1px solid #c8c8c8;
}

.accordion summary {
  cursor: pointer;
  padding: 1rem;
  font-weight: 600;
}

.accordion details[open] > summary {
  border-bottom: 1px solid #c8c8c8;
}

.accordion details > :not(summary) {
  margin: 0;
  padding: 1rem;
}

The open attribute reflects whether a <details> panel is expanded. The CSS selector details[open] lets you change its appearance without managing a separate state variable. See MDN’s details element reference for the element’s behavior and browser availability.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose whether panels open independently or exclusively

Allow multiple panels to remain open

Leave the name attribute off each <details> element, as in the first example. Visitors can expand several items and keep their contents visible while reading.

#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Keep only one panel open at a time

Give every disclosure in the group the same name value:

<details name="faq">
  <summary>First question</summary>
  <p>First answer.</p>
</details>
<details name="faq">
  <summary>Second question</summary>
  <p>Second answer.</p>
</details>

In an exclusive group, opening one disclosure closes another in the same group. This behavior is defined by the HTML Standard’s interactive elements specification.

Make the accordion usable

  • Keep <summary> as the first child of each <details>, and use text that clearly identifies the content it reveals.
  • Make the summary area comfortably large to activate, and preserve a visible keyboard-focus indicator. Avoid removing the browser’s focus outline unless you replace it with a clear alternative.
  • Check the finished design in the browsers and with the assistive technologies your audience uses. Native disclosure elements provide a useful baseline, but styling and behavior should be checked in the actual interface.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When native disclosure is not the right fit

A checkbox-and-label technique can expose a CSS state, but it requires careful label association, focus handling, keyboard behavior, and assistive-technology testing. For ordinary show-and-hide content, native disclosure is the more direct option.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If the design requires a richer button-and-panel widget, the W3C’s accordion pattern describes a different approach using buttons, aria-expanded, and aria-controls. Its example includes JavaScript and CSS; it is not the same no-script native disclosure pattern shown here.

Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.