Component

Basic Accordion

Simple documentation accordion with chevron rotation and smooth height animation. Clean, accessible, and ready for knowledge bases and developer docs.

  • Component
  • Tailwind
  • HTML
  • MIT

Preview

Live component

Interactive preview
Open preview
9:41 100%
devsnips.dev/library/tailwind/components/accordions/basic-accordion/
fluid · no fixed width 100%
No dependencies Production-ready

Install

Add to your project

terminal
npx devsnips add Tailwind/Components/Accordions/basic-accordion
registry path: Tailwind/Components/Accordions/basic-accordion

Source

Implementation

code.html
<!--
Snippet Name: Basic Accordion
Description: Simple documentation accordion with chevron rotation and smooth height animation.
Author: DevSnips Contributors
Usage Example: Drop into a docs/knowledge-base layout. Each item toggles independently.
-->
<div class="divide-y divide-gray-200 border-y border-gray-200" data-accordion="basic">
  <div class="group" data-accordion-item>
    <h3>
      <button
        type="button"
        id="basic-trigger-1"
        aria-controls="basic-panel-1"
        aria-expanded="false"
        class="accordion-trigger flex w-full items-center justify-between gap-4 py-4 text-left focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 rounded-md"
      >
        <span class="text-sm font-medium text-gray-900">Getting started with the CLI</span>
        <svg class="accordion-chevron h-5 w-5 shrink-0 text-gray-400 transition-transform duration-300 ease-out" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
          <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
        </svg>
      </button>
    </h3>
    <div
      id="basic-panel-1"
      role="region"
      aria-labelledby="basic-trigger-1"
      class="accordion-panel grid grid-rows-[0fr] transition-[grid-template-rows] duration-300 ease-out"
    >
      <div class="overflow-hidden">
        <div class="pb-4 pr-8 text-sm leading-relaxed text-gray-600">
          Install the CLI from npm, then run <code class="rounded bg-gray-100 px-1.5 py-0.5 text-[13px] font-medium text-gray-800">devsnips init</code> to scaffold a new project. This creates a folder structure that matches the component family layout used across the library.
        </div>
      </div>
    </div>
  </div>

  <div class="group" data-accordion-item>
    <h3>
      <button
        type="button"
        id="basic-trigger-2"
        aria-controls="basic-panel-2"
        aria-expanded="false"
        class="accordion-trigger flex w-full items-center justify-between gap-4 py-4 text-left focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 rounded-md"
      >
        <span class="text-sm font-medium text-gray-900">Configuring environment variables</span>
        <svg class="accordion-chevron h-5 w-5 shrink-0 text-gray-400 transition-transform duration-300 ease-out" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
          <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
        </svg>
      </button>
    </h3>
    <div
      id="basic-panel-2"
      role="region"
      aria-labelledby="basic-trigger-2"
      class="accordion-panel grid grid-rows-[0fr] transition-[grid-template-rows] duration-300 ease-out"
    >
      <div class="overflow-hidden">
        <div class="pb-4 pr-8 text-sm leading-relaxed text-gray-600">
          Copy the example file to <code class="rounded bg-gray-100 px-1.5 py-0.5 text-[13px] font-medium text-gray-800">.env.local</code> and fill in your API keys. Variables are loaded automatically and validated at startup, so the app fails fast if a required value is missing.
        </div>
      </div>
    </div>
  </div>

  <div class="group" data-accordion-item>
    <h3>
      <button
        type="button"
        id="basic-trigger-3"
        aria-controls="basic-panel-3"
        aria-expanded="false"
        class="accordion-trigger flex w-full items-center justify-between gap-4 py-4 text-left focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 rounded-md"
      >
        <span class="text-sm font-medium text-gray-900">Deploying to production</span>
        <svg class="accordion-chevron h-5 w-5 shrink-0 text-gray-400 transition-transform duration-300 ease-out" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
          <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
        </svg>
      </button>
    </h3>
    <div
      id="basic-panel-3"
      role="region"
      aria-labelledby="basic-trigger-3"
      class="accordion-panel grid grid-rows-[0fr] transition-[grid-template-rows] duration-300 ease-out"
    >
      <div class="overflow-hidden">
        <div class="pb-4 pr-8 text-sm leading-relaxed text-gray-600">
          Push to the <code class="rounded bg-gray-100 px-1.5 py-0.5 text-[13px] font-medium text-gray-800">main</code> branch to trigger the preview pipeline. Once CI passes and a reviewer approves, promote the preview to production from the dashboard with a single click.
        </div>
      </div>
    </div>
  </div>

  <script>
    (function () {
      const root = document.currentScript.closest('[data-accordion]');
      if (!root) return;
      root.querySelectorAll('[data-accordion-item]').forEach((item) => {
        const trigger = item.querySelector('.accordion-trigger');
        const panel = item.querySelector('.accordion-panel');
        const chevron = item.querySelector('.accordion-chevron');
        if (!trigger || !panel) return;
        const toggle = () => {
          const open = trigger.getAttribute('aria-expanded') === 'true';
          trigger.setAttribute('aria-expanded', String(!open));
          panel.classList.toggle('grid-rows-[1fr]', !open);
          panel.classList.toggle('grid-rows-[0fr]', open);
          if (chevron) chevron.style.transform = open ? '' : 'rotate(180deg)';
        };
        trigger.addEventListener('click', toggle);
      });
    })();
  </script>
</div>
115 lines UTF-8 · LF · Spaces: 2

AI-ready

Available to your agent.

This component is reachable through the DevSnips CLI, MCP server and Skills integrations — one registry, one resource path.

Resource path

devsnips://components/accordions/basic-accordion

Continue browsing

View all