<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pure CSS Accordion with Smooth Animations</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 2rem;
display: flex;
justify-content: center;
align-items: center;
}
.accordion {
width: 100%;
max-width: 600px;
background: white;
border-radius: 12px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.accordion-item {
border-bottom: 1px solid #eee;
}
.accordion-item:last-child {
border-bottom: none;
}
.toggle {
display: none;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1.5rem 2rem;
width: 100%;
cursor: pointer;
background: white;
font-size: 1.1rem;
font-weight: 600;
color: #333;
transition: background-color 0.2s ease, color 0.2s ease;
user-select: none;
}
.header:hover {
background: #f8f9ff;
color: #667eea;
}
.icon {
width: 24px;
height: 24px;
border-radius: 50%;
background: #667eea;
color: white;
display: flex;
align-items: center;
justify-content: center;
font-size: 0.9rem;
font-weight: bold;
transition: transform 0.3s ease;
}
.toggle:checked + .header .icon {
transform: rotate(45deg);
background: #764ba2;
}
.content {
max-height: 0;
opacity: 0;
overflow: hidden;
background: #fafbff;
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
padding: 0 2rem;
}
.toggle:checked ~ .content {
max-height: 400px; /* Adjust based on max content height */
opacity: 1;
padding: 1.5rem 2rem;
}
.content p {
line-height: 1.6;
color: #555;
margin-bottom: 1rem;
}
.content ul {
list-style: none;
padding-left: 0;
}
.content li {
padding: 0.5rem 0;
color: #555;
position: relative;
padding-left: 1.5rem;
}
.content li::before {
content: '▹';
position: absolute;
left: 0;
color: #667eea;
font-weight: bold;
}
@media (max-width: 768px) {
body {
padding: 1rem;
}
.header {
padding: 1.25rem 1.5rem;
font-size: 1rem;
}
.content {
padding: 0 1.5rem;
}
.toggle:checked ~ .content {
padding: 1.25rem 1.5rem;
}
}
</style>
</head>
<body>
<div class="accordion">
<div class="accordion-item">
<input type="checkbox" id="panel1" class="toggle">
<label for="panel1" class="header">
<span>What is a Pure CSS Accordion?</span>
<span class="icon">+</span>
</label>
<div class="content">
<p>A pure CSS accordion is a collapsible UI component built entirely with HTML and CSS, without any JavaScript. It uses the <code>:checked</code> pseudo-class on hidden checkboxes (or radio buttons) to toggle the visibility and smooth animations of content panels.</p>
</div>
</div>
<div class="accordion-item">
<input type="checkbox" id="panel2" class="toggle">
<label for="panel2" class="header">
<span>How do the animations work?</span>
<span class="icon">+</span>
</label>
<div class="content">
<p>Smooth transitions are achieved using CSS <code>transition</code> on properties like <code>max-height</code>, <code>opacity</code>, and <code>padding</code>. The <code>cubic-bezier</code> easing function provides a natural feel. The icon rotates on open using <code>transform: rotate(45deg)</code>.</p>
<ul>
<li>Closed: <code>max-height: 0; opacity: 0;</code></li>
<li>Open: <code>max-height: 400px; opacity: 1;</code></li>
</ul>
</div>
</div>
<div class="accordion-item">
<input type="checkbox" id="panel3" class="toggle">
<label for="panel3" class="header">
<span>Features of this implementation</span>
<span class="icon">+</span>
</label>
<div class="content">
<p>This accordion supports:</p>
<ul>
<li>Multiple panels open simultaneously</li>
<li>Smooth 400ms animations with easing</li>
<li>Hover effects on headers</li>
<li>Rotating + icon (turns to × when open)</li>
<li>Fully responsive design</li>
<li>Accessibility via labels and checkboxes</li>
<li>No JavaScript required</li>
</ul>
</div>
</div>
<div class="accordion-item">
<input type="checkbox" id="panel4" class="toggle">
<label for="panel4" class="header">
<span>Customization tips</span>
<span class="icon">+</span>
</label>
<div class="content">
<p>To customize:</p>
<ul>
<li>Change <code>max-height</code> in <code>.toggle:checked ~ .content</code> for longer content.</li>
<li>Use radio inputs with the same <code>name</code> attribute for single-open mode (e.g., <code>name="accordion"</code>).</li>
<li>Adjust <code>transition</code> duration or easing.</li>
<li>Add focus styles for keyboard navigation: <code>.header:focus { outline: 2px solid #667eea; }</code></li>
</ul>
</div>
</div>
</div>
</body>
</html>
This is a fully functional, pure CSS accordion with smooth animations. Copy-paste into an HTML file to test. It allows multiple panels to be open at once, features rotating icons, hover effects, and is responsive. For single-panel mode, replace checkboxes with radio inputs sharing a name attribute.