CSS Accordion
An accessible FAQ accordion built on native details and summary, with a rotating plus icon.
Is it free?
Yes, use it anywhere.
Does it need JavaScript?
No, it is native HTML.
<div class="accordion">
<details open>
<summary>Is it free?</summary>
<p>Yes, use it anywhere.</p>
</details>
<details>
<summary>Does it need JavaScript?</summary>
<p>No, it is native HTML.</p>
</details>
</div>
.accordion {
width: 260px;
border: 1px solid #e2e8f0;
border-radius: 12px;
background: #fff;
font: 14px/1.4 system-ui, sans-serif;
}
.accordion details + details {
border-top: 1px solid #e2e8f0;
}
.accordion summary {
display: flex;
justify-content: space-between;
align-items: center;
padding: 14px 16px;
color: #0f172a;
font-weight: 600;
list-style: none;
cursor: pointer;
}
.accordion summary::-webkit-details-marker {
display: none;
}
.accordion summary::after {
content: "+";
color: #64748b;
font-size: 20px;
line-height: 1;
transition: transform 0.2s ease;
}
.accordion details[open] summary::after {
transform: rotate(45deg);
}
.accordion p {
margin: 0;
padding: 0 16px 14px;
color: #475569;
}
About this CSS Accordion
This CSS Accordion is 44 lines of pure CSS (0.7 KB) with no JavaScript and no dependencies. It uses transitions, transforms and Flexbox. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
Customize it
The colors in this snippet. Search and replace them to match your brand:
#e2e8f0#fff#0f172a#64748b#475569
How to use this accordion
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.accordionclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.