Frequently Asked Questions

Pure CSS Accordion - No JavaScript Required!

Getting Started

The "checkbox hack" is a clever CSS technique that uses the <input type="checkbox"> element combined with the :checked pseudo-class to create interactive components without JavaScript.

When a checkbox is checked, you can use the sibling selector (~) to target and style other elements. This allows you to show/hide content, trigger animations, and create interactive UI components with pure CSS!

The smooth expand/collapse animation uses the max-height property with CSS transitions. Here's how it works:

  • By default, content has max-height: 0 and overflow: hidden
  • When the checkbox is checked, max-height changes to a large value (e.g., 1000px)
  • CSS transitions smoothly animate between these values
  • The icon rotation uses transform: rotate(180deg)

This technique is more reliable than animating height: auto, which doesn't work with CSS transitions.

Yes! This accordion uses checkboxes, which allow multiple items to be open simultaneously. Each checkbox maintains its own independent state.

If you want only one accordion open at a time (like a traditional accordion), you can use <input type="radio"> instead of checkboxes. Radio buttons with the same name attribute automatically deselect others when one is selected.

Customization

This template uses CSS custom properties (variables) defined in the :root selector. You can easily customize colors by changing these values:

  • --color-primary - Main accent color (currently blue)
  • --color-bg - Background color
  • --color-border - Border color
  • --color-header-bg - Accordion header background
  • --color-content-bg - Content area background

Find these variables near the top of the <style> section (around line 75-90).

Adding new accordion items is simple! Just copy the entire .accordion-item block and modify:

  1. Change the id attribute (e.g., "faq6", "faq7", etc.)
  2. Update the for attribute in the label to match the new id
  3. Replace the question text in the label
  4. Replace the answer content in the .accordion-content-inner div

Make sure each accordion item has a unique ID - this is crucial for the checkbox hack to work!

Absolutely! Look for the transition properties in the CSS:

  • .accordion-content - Controls expand/collapse speed (line ~200)
  • .accordion-icon - Controls icon rotation speed (line ~195)
  • .accordion-header - Controls background color change (line ~180)

Change the duration values (e.g., 0.4s to 0.6s for slower, or 0.2s for faster). You can also change ease to other timing functions like ease-in, ease-out, or cubic-bezier().

💡 Pro Tip

This accordion is fully accessible via keyboard! Press Tab to navigate between items and Space or Enter to expand/collapse. Screen readers will announce the state of each accordion item.