The user wants me to create a CSS-only accordion with smooth animations. This is a great use case for the :checked pseudo-class with hidden radio inputs or checkboxes, or using the and HTML elements with CSS styling.
Let me create something visually striking that matches the design aesthetic from the spec - dark theme, nice typography, smooth animations, and the indigo accent color.
I'll use the checkbox/radio hack approach for maximum control over the animations, or I could use the details/summary elements which are semantically better.
Actually, let me use the checkbox approach with hidden inputs - this gives us the smoothest animations since we can control height transitions better. The details/summary approach has limitations with height animations.
Let me create a beautiful accordion with:
- Dark theme matching the spec (#030304 background)
- Indigo accent colors for active states
- Smooth height and opacity transitions
- Nice typography with Inter font
- Icons that rotate when opened
- Staggered entrance animation
- Multiple items that can be open at once (checkbox approach) or single selection (radio approach)
I'll go with checkbox approach so multiple can be open, which is more flexible.
CSS-Only Accordion
A sleek, JavaScript-free accordion with smooth height animations using the checkbox hack technique.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS-Only Accordion</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', sans-serif;
background-color: #030304;
color: #ffffff;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 48px 24px;
}
h1 {
font-size: 36px;
font-weight: 500;
letter-spacing: -0.025em;
margin-bottom: 12px;
background: linear-gradient(to bottom, #fff, #e0e7ff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.subtitle {
color: #a1a1aa;
font-size: 14px;
margin-bottom: 48px;
font-weight: 300;
}
.accordion-container {
width: 100%;
max-width: 640px;
display: flex;
flex-direction: column;
gap: 12px;
}
/* Hide the checkbox */
.accordion-input {
position: absolute;
opacity: 0;
pointer-events: none;
}
/* Accordion item */
.accordion-item {
background: rgba(255, 255, 255, 0.03);
border: 1px solid rgba(255, 255, 255, 0.06);
border-radius: 12px;
overflow: hidden;
transition: all 0.3s ease;
}
.accordion-item:hover {
border-color: rgba(255, 255, 255, 0.1);
background: rgba(255, 255, 255, 0.05);
}
/* Label (header) */
.accordion-label {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px 24px;
cursor: pointer;
user-select: none;
transition: all 0.3s ease;
}
.accordion-label:hover {
background: rgba(255, 255, 255, 0.02);
}
.label-content {
display: flex;
align-items: center;
gap: 16px;
}
.label-icon {
width: 40px;
height: 40px;
border-radius: 10px;
background: linear-gradient(135deg, #6366f1, #4f46e5);
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
flex-shrink: 0;
}
.label-text h3 {
font-size: 16px;
font-weight: 500;
color: #ffffff;
margin-bottom: 2px;
}
.label-text p {
font-size: 12px;
color: #71717a;
font-weight: 300;
}
/* Arrow icon */
.arrow {
width: 24px;
height: 24px;
border-radius: 6px;
background: rgba(255, 255, 255, 0.05);
display: flex;
align-items: center;
justify-content: center;
transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.arrow svg {
width: 14px;
height: 14px;
stroke: #a1a1aa;
transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
/* Content panel */
.accordion-content {
max-height: 0;
overflow: hidden;
transition: max-height 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
.content-inner {
padding: 0 24px 24px 80px;
opacity: 0;
transform: translateY(-10px);
transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.content-inner p {
color: #a1a1aa;
font-size: 14px;
line-height: 1.7;
font-weight: 300;
}
.content-inner ul {
margin-top: 12px;
padding-left: 20px;
}
.content-inner li {
color: #a1a1aa;
font-size: 13px;
line-height: 1.8;
font-weight: 300;
}
.content-inner li::marker {
color: #6366f1;
}
/* Checked state */
.accordion-input:checked + .accordion-label .arrow {
transform: rotate(180deg);
background: rgba(99, 102, 241, 0.2);
}
.accordion-input:checked + .accordion-label .arrow svg {
stroke: #818cf8;
}
.accordion-input:checked + .accordion-label .label-text h3 {
color: #818cf8;
}
.accordion-input:checked ~ .accordion-content {
max-height: 300px;
}
.accordion-input:checked ~ .accordion-content .content-inner {
opacity: 1;
transform: translateY(0);
transition-delay: 0.15s;
}
.accordion-input:checked ~ .accordion-item {
border-color: rgba(99, 102, 241, 0.3);
}
/* Focus state for accessibility */
.accordion-input:focus-visible + .accordion-label {
outline: 2px solid #6366f1;
outline-offset: 2px;
}
/* Entrance animation */
.accordion-item {
opacity: 0;
transform: translateY(20px);
animation: fadeInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.accordion-item:nth-child(1) { animation-delay: 0.1s; }
.accordion-item:nth-child(2) { animation-delay: 0.2s; }
.accordion-item:nth-child(3) { animation-delay: 0.3s; }
.accordion-item:nth-child(4) { animation-delay: 0.4s; }
.accordion-item:nth-child(5) { animation-delay: 0.5s; }
@keyframes fadeInUp {
to {
opacity: 1;
transform: translateY(0);
}
}
/* Badge */
.badge {
font-size: 9px;
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0.05em;
padding: 4px 8px;
border-radius: 4px;
background: rgba(16, 185, 129, 0.15);
color: #34d399;
margin-left: auto;
margin-right: 16px;
}
.badge.purple {
background: rgba(168, 85, 247, 0.15);
color: #d8b4fe;
}
.badge.blue {
background: rgba(59, 130, 246, 0.15);
color: #93c5fd;
}
/* Divider line */
.divider {
width: 100%;
max-width: 640px;
height: 1px;
background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
margin: 24px 0;
}
/* Radio-style accordion (single open) section */
.radio-section h2 {
font-size: 14px;
font-weight: 400;
color: #71717a;
margin-bottom: 16px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.radio-accordion-input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.radio-accordion-item {
background: rgba(255, 255, 255, 0.03);
border: 1px solid rgba(255, 255, 255, 0.06);
border-radius: 12px;
overflow: hidden;
transition: all 0.3s ease;
margin-bottom: 8px;
}
.radio-accordion-label {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px 20px;
cursor: pointer;
user-select: none;
}
.radio-accordion-label span {
font-size: 14px;
font-weight: 400;
color: #e0e7ff;
}
.radio-indicator {
width: 20px;
height: 20px;
border-radius: 50%;
border: 2px solid rgba(255, 255, 255, 0.2);
position: relative;
transition: all 0.3s ease;
}
.radio-indicator::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(0);
width: 8px;
height: 8px;
border-radius: 50%;
background: #6366f1;
transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.radio-accordion-content {
max-height: 0;
overflow: hidden;
transition: max-height 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.radio-accordion-content-inner {
padding: 0 20px 16px 20px;
font-size: 13px;
color: #a1a1aa;
line-height: 1.6;
font-weight: 300;
}
.radio-accordion-input:checked + .radio-accordion-label .radio-indicator {
border-color: #6366f1;
}
.radio-accordion-input:checked + .radio-accordion-label .radio-indicator::after {
transform: translate(-50%, -50%) scale(1);
}
.radio-accordion-input:checked + .radio-accordion-label span {
color: #ffffff;
}
.radio-accordion-input:checked ~ .radio-accordion-content {
max-height: 200px;
}
.radio-accordion-input:focus-visible + .radio-accordion-label {
outline: 2px solid #6366f1;
outline-offset: 2px;
}
</style>
</head>
<body>
<h1>Frequently Asked Questions</h1>
<p class="subtitle">Pure CSS accordion with smooth animations</p>
<div class="accordion-container">
<!-- Item 1 -->
<div class="accordion-item">
<input type="checkbox" id="accordion-1" class="accordion-input" checked>
<label for="accordion-1" class="accordion-label">
<div class="label-content">
<div class="label-icon">⚡</div>
<div class="label-text">
<h3>How does the animation work?</h3>
<p>Pure CSS magic with cubic-bezier easing</p>
</div>
</div>
<span class="badge">Popular</span>
<div class="arrow">
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
</svg>
</div>
</label>
<div class="accordion-content">
<div class="content-inner">
<p>This accordion uses the CSS :checked pseudo-class with hidden checkbox inputs. When clicked, the label toggles the checkbox state, which we style using adjacent sibling selectors.</p>
<ul>
<li>No JavaScript required</li>
<li>Smooth height transitions with cubic-bezier easing</li>
<li>Staggered content fade-in animation</li>
<li>Full keyboard accessibility support</li>
</ul>
</div>
</div>
</div>
<!-- Item 2 -->
<div class="accordion-item">
<input type="checkbox" id="accordion-2" class="accordion-input">
<label for="accordion-2" class="accordion-label">
<div class="label-content">
<div class="label-icon">🎨</div>
<div class="label-text">
<h3>Can I customize the colors?</h3>
<p>Easy theming with CSS variables</p>
</div>
</div>
<span class="badge purple">New</span>
<div class="arrow">
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
</svg>
</div>
</label>
<div class="accordion-content">
<div class="content-inner">
<p>Absolutely! All colors are defined inline and can be easily converted to CSS custom properties for dynamic theming. The design uses a dark theme with indigo accents that can be modified to match any brand.</p>
</div>
</div>
</div>
<!-- Item 3 -->
<div class="accordion-item">
<input type="checkbox" id="accordion-3" class="accordion-input">
<label for="accordion-3" class="accordion-label">
<div class="label-content">
<div class="label-icon">📱</div>
<div class="label-text">
<h3>Is it mobile responsive?</h3>
<p>Works on all screen sizes</p>
</div>
</div>
<div class="arrow">
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
</svg>
</div>
</label>
<div class="accordion-content">
<div class="content-inner">
<p>Yes! The accordion is fully responsive with fluid typography and spacing. It uses percentage-based widths and flexbox for layout, ensuring it looks great on mobile, tablet, and desktop devices.</p>
</div>
</div>
</div>
<!-- Item 4 -->
<div class="accordion-item">
<input type="checkbox" id="accordion-4" class="accordion-input">
<label for="accordion-4" class="accordion-label">
<div class="label-content">
<div class="label-icon">♿</div>
<div class="label-text">
<h3>What about accessibility?</h3>
<p>Keyboard navigation & screen readers</p>
</div>
</div>
<span class="badge blue">A11y</span>
<div class="arrow">
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
</svg>
</div>
</label>
<div class="accordion-content">
<div class="content-inner">
<p>The accordion is fully accessible with proper focus states using :focus-visible. Users can navigate with Tab and toggle items with Space or Enter. The checkbox inputs provide semantic meaning for screen readers.</p>
</div>
</div>
</div>
</div>
<div class="divider"></div>
<!-- Radio-style (single selection) -->
<div class="radio-section">
<h2>Single Selection Mode</h2>
<div class="accordion-container">
<div class="radio-accordion-item">
<input type="radio" name="radio-accordion" id="radio-1" class="radio-accordion-input" checked>
<label for="radio-1" class="radio-accordion-label">
<span>Option One - Default Selection</span>
<div class="radio-indicator"></div>
</label>
<div class="radio-accordion-content">
<div class="radio-accordion-content-inner">
This uses radio inputs instead of checkboxes, allowing only one item to be open at a time. Great for exclusive options.
</div>
</div>
</div>
<div class="radio-accordion-item">
<input type="radio" name="radio-accordion" id="radio-2" class="radio-accordion-input">
<label for="radio-2" class="radio-accordion-label">
<span>Option Two - Alternative Choice</span>
<div class="radio-indicator"></div>
</label>
<div class="radio-accordion-content">
<div class="radio-accordion-content-inner">
When you select this option, the previous one automatically closes. This mimics traditional accordion behavior.
</div>
</div>
</div>
<div class="radio-accordion-item">
<input type="radio" name="radio-accordion" id="radio-3" class="radio-accordion-input">
<label for="radio-3" class="radio-accordion-label">
<span>Option Three - Another Possibility</span>
<div class="radio-indicator"></div>
</label>
<div class="radio-accordion-content">
<div class="radio-accordion-content-inner">
Radio-based accordions are perfect for FAQs where you want users to focus on one answer at a time.
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Key Features
| Feature | Implementation |
|---|
| No JavaScript | Uses :checked pseudo-class with hidden inputs |
| Smooth Animation | cubic-bezier(0.16, 1, 0.3, 1) easing curve |
| Height Transition | max-height from 0 to fixed value |
| Content Fade | Opacity + transform on inner content |
| Multi-open Mode | Checkbox inputs (top section) |
| Single-open Mode | Radio inputs (bottom section) |
| Keyboard Access | Tab navigation + Space/Enter to toggle |
| Focus States | :focus-visible outline styling |
| Staggered Entrance | animation-delay on each item |