Remember the days when creating an FAQ section meant cobbling together a mess of divs, jQuery dependencies, and praying it wouldn't break your site? I sure do. I once spent an entire bank holiday debugging a client's accordion that mysteriously collapsed (like my will to live) every time someone clicked the third question. Good times.
But here's some brilliant news — if you're using 365i's AI FAQ Generator to create schema-powered FAQs (and if you're not, what are you waiting for?), I'm about to show you how to transform that structured markup into a gorgeous CSS FAQ accordion that even your pickiest design friends will compliment.
The best part? No jQuery required. Just pure CSS magic with a sprinkle of vanilla JavaScript. I've built dozens of CSS FAQ accordions over the years, and this approach is hands-down the most elegant solution I've found. Let's dive in!

Why Schema-Based Accordions Are Web Design Gold
Before we get to the fun styling bits for our CSS FAQ accordion, let's talk about why this approach is absolutely brilliant:
- SEO superpowers: The schema markup helps Google understand your content, potentially landing you those coveted rich snippets in search results.
- Accessibility built-in: The semantic structure is naturally more accessible than DIY solutions.
- Maintenance simplicity: Update your FAQs in one place, and both the schema and the visual accordion stay in sync.
As the team at Schema.org states:
"A FAQPage contains a collection of questions and answers pertaining to a particular topic... Marking up FAQ content with structured data can make your content eligible to appear with a rich result on Search and with an Action on the Assistant."

The Starting Point: Generate Your FAQ Schema
First things first, we need to generate our schema-powered FAQs. Here's the quickest route:
- Head over to 365i's AI FAQ Generator
- Enter your page URL (or create FAQs manually)
- Let the AI work its magic
- Choose "Microdata" as your output format
- Copy the generated code to your website
If you're new to the AI FAQ Generator, it's an absolute game-changer. As I mentioned in a previous post about Position Zero SEO strategies, schema markup is one of the most powerful tools for getting your content into those prime positions.
Once we have our Microdata Schema we can create our CSS FAQ accordion with 1 copy & paste!
The CSS Magic: Making Your FAQs Look Gorgeous
Now for the fun part! Here's the CSS that will transform your bland schema markup into an interactive accordion:
<style>
/* The "Make My FAQs Look Gorgeous" CSS - 2025 Edition */
.faqcss div[itemtype="https://schema.org/FAQPage"] {
margin: 2rem auto;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}
/* Question styling - the clickable headers */
.faqcss div[itemtype="https://schema.org/Question"] {
margin-bottom: 1.25rem;
border: 1px solid rgba(0, 0, 0, 0.1);
border-radius: 8px;
background: #fff;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
transition: all 0.2s ease;
overflow: hidden;
}
.faqcss div[itemtype="https://schema.org/Question"]:hover {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
transform: translateY(-2px);
}
/* Question headers */
.faqcss h2[itemprop="name"] {
padding: 1.25rem 3rem 1.25rem 1.5rem;
margin: 0;
font-size: 0.9rem;
font-weight: 500;
color: #111;
position: relative;
cursor: pointer;
user-select: none;
transition: background-color 0.2s;
}
/* The fancy plus/minus icon */
.faqcss h2[itemprop="name"]::after {
content: '+';
position: absolute;
right: 1.5rem;
top: 50%;
transform: translateY(-50%);
font-size: 1.5rem;
color: #0073aa;
transition: all 0.2s;
}
/* Answer container styling */
.faqcss div[itemtype="https://schema.org/Answer"] {
height: 0;
overflow: hidden;
transition: height 0.3s ease-out;
padding: 0 1.5rem;
}
/* The actual answer text */
.faqcss div[itemprop="text"] {
padding: 1.5rem;
color: #444;
line-height: 1.6;
}
.faqcss div[itemprop="text"] p {
margin-top: 0;
}
/* Active state styling (when expanded) */
.faqcss div[itemtype="https://schema.org/Question"].active {
background: #f8f9fa;
}
.faqcss div[itemtype="https://schema.org/Question"].active h2[itemprop="name"] {
color: #0073aa;
background: rgba(0, 115, 170, 0.05);
}
.faqcss div[itemtype="https://schema.org/Question"].active h2[itemprop="name"]::after {
content: '−';
transform: translateY(-50%) rotate(0deg);
}
/* The footer link styling */
.faqcss div[itemtype="https://schema.org/FAQPage"] > p {
text-align: center;
margin-top: 2rem;
font-size: 0.95rem;
opacity: 0.8;
}
.faqcss div[itemtype="https://schema.org/FAQPage"] > p a {
color: #0073aa;
text-decoration: none;
font-weight: 500;
}
.faqcss div[itemtype="https://schema.org/FAQPage"] > p a:hover {
text-decoration: underline;
}
/* Responsive adjustments for small screens */
@media (max-width: 768px) {
.faqcss h2[itemprop="name"] {
padding: 1rem 2.5rem 1rem 1rem;
font-size: 0.75rem;
}
.faqcss h2[itemprop="name"]::after {
right: 0.75rem;
}
.faqcss div[itemprop="text"] {
padding-bottom: 0.75rem;
}
}
/* We'll handle the column layout via JavaScript instead of media queries */
/* This allows us to check the container width rather than viewport width */
/<style>The JavaScript Sprinkle: Making It Interactive
Now, let's add a bit of JavaScript magic to make our CSS FAQ accordion interactive. This is where the real magic happens:
<script>
document.addEventListener('DOMContentLoaded', function() {
// First, check if any FAQ elements exist on this page
const faqContainer = document.querySelector('.faqcss div[itemtype="https://schema.org/FAQPage"]');
// Only run the FAQ code if we actually found FAQs
if (faqContainer) {
const questions = document.querySelectorAll('.faqcss div[itemtype="https://schema.org/Question"]');
// Add this function to handle column layout based on container width
function adjustFAQColumns() {
const container = document.querySelector('.faqcss');
if (!container) return;
// Check container width, not viewport width
if (container.offsetWidth >= 1025) {
// Wide container - use two columns
faqContainer.style.columnCount = "2";
faqContainer.style.columnGap = "40px";
// Make sure FAQ items don't break across columns
questions.forEach(item => {
item.style.breakInside = "avoid";
item.style.pageBreakInside = "avoid";
item.style.display = "inline-block";
item.style.width = "100%";
});
// Footer spans all columns if present
const footer = faqContainer.querySelector('p');
if (footer) {
footer.style.columnSpan = "all";
}
} else {
// Narrow container - use one column
faqContainer.style.columnCount = "1";
faqContainer.style.columnGap = "0";
// Reset any column-specific styles
questions.forEach(item => {
item.style.display = "block";
});
}
}
// Call it initially and on resize
adjustFAQColumns();
window.addEventListener('resize', adjustFAQColumns);
questions.forEach(function(question, index) { // Added index parameter here
const header = question.querySelector('h2[itemprop="name"]');
const answer = question.querySelector('div[itemtype="https://schema.org/Answer"]');
const answerContent = question.querySelector('div[itemprop="text"]');
// Initialize collapsed state
answer.style.height = '0px';
// If this is the first question, open it automatically after a tiny delay
if (index === 0) {
setTimeout(function() {
question.classList.add('active');
answer.style.height = answerContent.offsetHeight + 'px';
}, 50); // Small delay to ensure proper height calculation
}
header.addEventListener('click', function() {
const isActive = question.classList.contains('active');
// Close all questions first
questions.forEach(q => {
q.classList.remove('active');
q.querySelector('div[itemtype="https://schema.org/Answer"]').style.height = '0px';
});
// If wasn't active, open this question
if (!isActive) {
question.classList.add('active');
answer.style.height = answerContent.offsetHeight + 'px';
}
});
});
// Bonus: Handle window resizing to fix heights when screen size changes
window.addEventListener('resize', function() {
const activeQuestion = document.querySelector('.faqcss div[itemtype="https://schema.org/Question"].active');
if (activeQuestion) {
const answer = activeQuestion.querySelector('div[itemtype="https://schema.org/Answer"]');
const answerContent = activeQuestion.querySelector('div[itemprop="text"]');
answer.style.height = answerContent.offsetHeight + 'px';
}
});
}
});
</script>This JavaScript does a few clever things:
- Auto-opens the first question (so users know it's interactive)
- Handles the expand/collapse functionality
- Resizes answer heights when the window changes size
- Automatically switches between one and two-column layouts based on container width
Putting It All Together: Implementation Steps
Now let's put everything together:
- Generate your FAQ schema using the AI FAQ Generator (choose "Microdata" format)
- Wrap your schema markup in a div with class
faqcss:<div class="faqcss"> <!-- Your FAQ schema markup goes here --></div> - Add the CSS to your stylesheet or in a
<style>tag in your<head> - Add the JavaScript just before your closing
</body>tag
And voilà! Your boring FAQ schema has transformed into an interactive, stylish accordion that both users and search engines will love. (See our FAQ accordion below for how it will look without customization)
This video shows how quick and easy it is to do. Takes just 1 minute!
Beyond the Basics: Customizations
The CSS I've provided is just a starting point for your CSS FAQ accordion. Here are some ways you could customize it:
- Change the colors: Update the color values to match your brand
- Adjust the animations: Modify the transition properties for different effects
- Tweak the spacing: Adjust padding and margins to fit your design system
If you're hosting with us on our lightning-fast WordPress hosting, you can easily add this code to your theme's stylesheet and functions.php file (for the JavaScript). Or, if you prefer, you can use a plugin like Code Snippets to add them without editing theme files.
Why This Matters for SEO (And Your Users)
The beauty of this approach is that it serves both masters: search engines and actual humans.
For search engines, the structured data helps them understand your content better, potentially earning you those coveted rich snippets. And as we discussed in our post about FAQ Schema techniques, this can significantly boost your CTR.
For humans, the interactive CSS FAQ accordion provides a clean, intuitive way to navigate through your FAQs without overwhelming them with walls of text.
According to a study by the Nielsen Norman Group:
"Progressive disclosure is one of the best ways to reduce UI complexity. When used correctly, accordions can dramatically improve the user experience by allowing users to scan topics quickly and only expand those they care about."

Frequently Asked Questions About CSS FAQ Accordions
How do I add FAQ schema to my WordPress site?
To add FAQ schema to your WordPress site, use the 365i AI FAQ Generator to create structured markup. Enter your page URL, let the AI generate relevant questions and answers, select your preferred format (JSON-LD, Microdata, RDFa, or HTML), and copy the code. For WordPress sites, you can paste JSON-LD directly into your header or use a schema plugin. Alternatively, place Microdata directly in your page content where you want the FAQs to appear.
Do CSS FAQ accordions work on mobile devices?
Yes, CSS FAQ accordions are fully responsive on mobile devices when properly implemented. The code provided in this guide includes media queries that automatically adjust spacing, font sizes, and touch targets for smaller screens. The accordion collapses to a single column on mobile devices, ensuring optimal readability. The JavaScript also handles touch events correctly, making the accordion fully functional on smartphones and tablets without any additional plugins or dependencies.
What’s the difference between JSON-LD and Microdata for FAQ schema?
JSON-LD embeds schema as a script in your page’s head or body without affecting the visible HTML structure, making it Google’s preferred format for clean separation. Microdata, used in this accordion tutorial, integrates schema directly into your HTML elements with attributes like itemscope and itemprop. Microdata allows your visible content and schema to be perfectly aligned, making it ideal for creating visual accordions that are also schema-compliant. Both formats are fully supported by search engines.
How long does it take for FAQ schema to appear in Google search results?
FAQ schema typically takes 1-4 weeks to appear in Google search results after implementation. Google must first crawl your page, process the schema, and determine if it meets quality guidelines. You can speed up this process by submitting your URL for indexing in Google Search Console and using the Rich Results Test tool to validate your schema. Not all pages with valid FAQ schema will receive rich results, as Google’s algorithms ultimately decide which pages deserve enhanced listings.
Can I customize the colors and styling of the CSS FAQ accordion?
Yes, you can fully customize the FAQ accordion’s appearance by modifying the CSS variables. Change colors by updating the hex codes (e.g., #0073aa to your brand color), adjust spacing by modifying padding and margin values, and alter animations by changing transition properties. The accordion uses standard CSS properties, making it easily adaptable to match your website’s design system. For WordPress users, add custom CSS via your theme’s Customizer or a plugin like 365i’s AI FAQ Generator.
Why isn’t my FAQ accordion working after I added the code?
If your FAQ accordion isn’t working, check these common issues:
- Verify you wrapped the schema in a div with class “faqcss”
- Confirm the JavaScript is loading after the FAQ content (place it before closing body tag)
- Check browser console for JavaScript errors
- Ensure your schema structure matches the expected selectors in the JavaScript
- Verify no CSS conflicts by inspecting elements.
Most issues occur when the HTML structure doesn’t match what the JavaScript expects or when scripts load in the wrong order.
How many FAQs should I include on my page for SEO?
For optimal SEO benefit, include 4-8 FAQs on your page that address genuine user questions with concise, valuable answers. Google typically displays 2-3 FAQs in rich results, so prioritize your most important questions at the top. While you can technically add more, excessive FAQs might appear as keyword stuffing to search engines. Quality trumps quantity—each FAQ should provide unique value. Use the 365i AI FAQ Generator to create relevant questions based on your content.
Learn more about our WordPress Hosting.
To add FAQ schema to your WordPress site, use the 365i AI FAQ Generator to create structured markup. Enter your page URL, let the AI generate relevant questions and answers, select your preferred format (JSON-LD, Microdata, RDFa, or HTML), and copy the code. For WordPress sites, you can paste JSON-LD directly into your header or use a schema plugin. Alternatively, place Microdata directly in your page content where you want the FAQs to appear.
Final Thoughts
What I love most about this solution is how it elegantly bridges the gap between technical SEO and user experience. Too often, we see these as separate concerns, but they're really two sides of the same coin.
By starting with schema-powered FAQs from the AI FAQ Generator and enhancing them with this CSS and JavaScript, you're creating a solution that works for everyone.
If you're looking for more ways to optimize your WordPress site, check out our guide on Top WordPress Hosting with AI. And remember, if you run into any issues implementing this accordion, our support team is always here to help.
Have you implemented FAQ schema on your site? Let me know in the comments how it's working for you!
Note: This article was last updated on May 21, 2025, to ensure all code is compatible with current browser standards.

