Ana içeriğe atla

CSS-only Tailwind CSS collapsible panel using native

. Show and hide content sections without JavaScript. WCAG AA accessible, works with Django, HTMX, Laravel, React, and any stack.

{% trans "Collapsible components allow users to expand and collapse sections of content. Built with a hidden checkbox pattern, collapsibles work without any JavaScript and support animated transitions via CSS grid." %}

Yalnızca CSS, JavaScript gerekmez. WCAG AA erişilebilir ve çerçeveden bağımsız — Django, HTMX, Laravel, React ve tüm yığınlarla çalışır.

Sınıf Tip Tanım
collapsibleTemelGizli bir onay kutusuyla yönlendirilen katlanabilir konteyner
collapsible-toggleDeğiştiriciAçık/kapalı durumunu kontrol eden gizli onay kutusu girişi
collapsible-titleDeğiştiriciKatlanabilirliği değiştiren tıklanabilir etiket
collapsible-contentDeğiştiriciAnimasyonlu içerik alanı açıldığında ortaya çıkıyor
collapsible-arrowDeğiştiriciBaşlığa dönen bir ok göstergesi ekler
collapsible-groupDeğiştiriciAkordeon tarzı gruplandırılmış katlanabilir malzemeler için sarıcı
collapsible-overlayDeğiştiriciÇekmece tarzı katlanabilir parçalar için kaplama çeşidi
collapsible-peekDeğiştiriciDaraltıldığında içeriğe kısa bir bakış gösterir
is-collapsible-openDeğiştiriciAçık durumu zorlamak için JS uygulamalı sınıf
is-collapsible-closeDeğiştiriciKapalı durumu zorlamak için JS uygulamalı sınıf

Temel Kullanım

Gizli bir onay kutusu açma/kapama durumunu yönlendirir. label bunu tetikler; daraltılabilir içerik div açık animasyonu gerçekleştirir.

This content is hidden until expanded.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<div class="collapsible border border-base-soft rounded-lg">
  <input type="checkbox" class="collapsible-toggle" id="col-basic" />
  <label for="col-basic" class="collapsible-title px-4 py-3 font-medium">Click to expand</label>
  <div class="collapsible-content">
    <div>
      <div class="px-4 pb-3 text-sm opacity-70">
        This content is hidden until expanded.
      </div>
    </div>
  </div>
</div>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import { useCollapsible } from 'frutjam/react'

export default function CollapsibleDemo() {
  const collapsible = useCollapsible()
  return (
    <div ref={collapsible.ref} className="collapsible border border-base-soft rounded-lg">
      <button className="collapsible-title px-4 py-3 font-medium" onClick={collapsible.toggle}>Click to expand</button>
      <div className="collapsible-content">
        <div>
          <div className="px-4 pb-3 text-sm opacity-70">
            This content is hidden until expanded.
          </div>
        </div>
      </div>
    </div>
  )
}

Ok Göstergeli

Açık/kapalı durumunu yansıtan dönen bir şerit elde etmek için etikete daraltılabilir ok ekleyin.

Frutjam is a Tailwind CSS v4 component library built with CSS utilities and a PostCSS plugin.
html
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<div class="collapsible border border-base-soft rounded-lg">
  <input type="checkbox" class="collapsible-toggle" id="col-arrow" />
  <label for="col-arrow" class="collapsible-title collapsible-arrow px-4 py-3 font-medium">What is Frutjam?</label>
  <div class="collapsible-content">
    <div>
      <div class="px-4 pb-3 text-sm opacity-70">
        Frutjam is a Tailwind CSS v4 component library built with CSS utilities and a PostCSS plugin.
      </div>
    </div>
  </div>
</div>

Çoklu Katlanabilirler

Content for the first section.
Content for the second section.
Content for the third section.
html
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<div class="flex flex-col gap-2">
  <div class="collapsible border border-base-soft rounded-lg">
    <input type="checkbox" class="collapsible-toggle" id="col-1" />
    <label for="col-1" class="collapsible-title collapsible-arrow px-4 py-3 font-medium">Section One</label>
    <div class="collapsible-content">
      <div>
        <div class="px-4 pb-3 text-sm opacity-70">Content for the first section.</div>
      </div>
    </div>
  </div>

  <div class="collapsible border border-base-soft rounded-lg">
    <input type="checkbox" class="collapsible-toggle" id="col-2" />
    <label for="col-2" class="collapsible-title collapsible-arrow px-4 py-3 font-medium">Section Two</label>
    <div class="collapsible-content">
      <div>
        <div class="px-4 pb-3 text-sm opacity-70">Content for the second section.</div>
      </div>
    </div>
  </div>

  <div class="collapsible border border-base-soft rounded-lg">
    <input type="checkbox" class="collapsible-toggle" id="col-3" />
    <label for="col-3" class="collapsible-title collapsible-arrow px-4 py-3 font-medium">Section Three</label>
    <div class="collapsible-content">
      <div>
        <div class="px-4 pb-3 text-sm opacity-70">Content for the third section.</div>
      </div>
    </div>
  </div>
</div>

Varsayılan Olarak Aç

Paneli açmaya başlamak için onay kutusu girişine checked ekleyin.

This content is visible on initial load.
html
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<div class="collapsible border border-base-soft rounded-lg">
  <input type="checkbox" class="collapsible-toggle" id="col-open" checked />
  <label for="col-open" class="collapsible-title collapsible-arrow px-4 py-3 font-medium">Open by default</label>
  <div class="collapsible-content">
    <div>
      <div class="px-4 pb-3 text-sm opacity-70">
        This content is visible on initial load.
      </div>
    </div>
  </div>
</div>

JS Kontrollü

Onay kutusu kullanmak yerine sarmalayıcı öğesinde daraltılabilir-aç seçeneğini değiştirin; tetikleyici başka bir yerde bulunduğunda kullanışlıdır.

No hidden checkbox needed — state is managed by the collapsible-open class.
html
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<div class="collapsible collapsible-open border border-base-soft rounded-lg" id="js-col">
  <button
    class="collapsible-title collapsible-arrow px-4 py-3 font-medium"
    onclick="this.closest('.collapsible').classList.toggle('collapsible-open')"
  >
    Toggle via JS (starts open)
  </button>
  <div class="collapsible-content">
    <div>
      <div class="px-4 py-3 text-sm opacity-70 border-t border-base-soft">
        No hidden checkbox needed — state is managed by the <code>collapsible-open</code> class.
      </div>
    </div>
  </div>
</div>

Gözetleme Varyantı

daraltılabilir peek, degrade geçişli ve kaplama tetikleyicili kırpılmış bir önizleme gösterir. Daraltıldığında ne kadar içeriğin görüneceğini kontrol etmek için --peek-height değerini geçersiz kılın.

Frutjam is a Tailwind CSS v4 component library built around a PostCSS plugin architecture. Every component is a set of @utility definitions that integrate natively with Tailwind's utility pipeline.

Theming is handled entirely through CSS custom properties. Swap themes by setting a data-theme attribute on any container, or override individual tokens inline.

Components ship with sensible defaults and are designed to compose cleanly.

html
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<div class="collapsible collapsible-peek rounded-xl border border-base-soft" style="--peek-height: 5rem;">
  <input type="checkbox" class="collapsible-toggle" id="col-peek" />
  <div class="collapsible-content">
    <div class="p-4 text-sm leading-relaxed">
      <p>Frutjam is a Tailwind CSS v4 component library built around a PostCSS plugin architecture. Every component is a set of <code>@utility</code> definitions that integrate natively with Tailwind's utility pipeline.</p>
      <p class="mt-3">Theming is handled entirely through CSS custom properties. Swap themes by setting a <code>data-theme</code> attribute on any container, or override individual tokens inline.</p>
      <p class="mt-3">Components ship with sensible defaults and are designed to compose cleanly.</p>
    </div>
  </div>
  <label for="col-peek" class="collapsible-overlay">
    <span class="btn btn-sm">Read more</span>
  </label>
</div>

JS ve Tepki Yardımcısı

Programlı kontrol ve herhangi bir tetikleyicide otomatik aria-expanded senkronizasyonu için frutjam/js'den createCollapsible'ı veya frutjam/react'tan useCollapsible'u kullanın.

Controlled section
Toggled by the external button above.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<button class="btn btn-sm mb-3" id="col-helper-btn">Toggle</button>
<div class="collapsible border border-base-soft rounded-lg" id="js-collapsible">
  <div class="collapsible-title collapsible-arrow px-4 py-3 font-medium">Controlled section</div>
  <div class="collapsible-content">
    <div>
      <div class="px-4 pb-3 text-sm opacity-70">Toggled by the external button above.</div>
    </div>
  </div>
</div>
<script type="module">
  import { createCollapsible } from 'frutjam/js'
  const col = createCollapsible(document.getElementById('js-collapsible'))
  document.getElementById('col-helper-btn').onclick = () => col.toggle()
</script>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import { useCollapsible } from 'frutjam/react'

export default function CollapsibleDemo() {
  const collapsible = useCollapsible()
  return (
    <>
      <button className="btn btn-sm mb-3" onClick={collapsible.toggle}>Toggle</button>
      <div ref={collapsible.ref} className="collapsible border border-base-soft rounded-lg">
        <div className="collapsible-title collapsible-arrow px-4 py-3 font-medium">Controlled section</div>
        <div className="collapsible-content">
          <div>
            <div className="px-4 pb-3 text-sm opacity-70">Toggled by the external button above.</div>
          </div>
        </div>
      </div>
    </>
  )
}

Katlanabilir gruplu Harici Tetikleyici

Etiketlerin .collapsible dışında kalmasına izin vermek için collapsible-group içine bir tetikleyici ve bir daraltılabilir öğe sarın is-collapsible-open ve is-collapsible-close yoluyla açık/kapalı durumuna yanıt verir.

Section A
This content is toggled by the button above, which lives outside .collapsible but inside .collapsible-group.
html
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<div class="collapsible-group border border-base-soft rounded-lg p-4 flex flex-col gap-3">
  <div class="flex items-center justify-between">
    <span class="font-medium">Section A</span>
    <label for="cg-1" class="btn btn-sm btn-ghost">
      <span class="is-collapsible-close">Expand</span>
      <span class="is-collapsible-open">Collapse</span>
    </label>
  </div>
  <div class="collapsible">
    <input type="checkbox" class="collapsible-toggle" id="cg-1" />
    <div class="collapsible-content">
      <div>
        <div class="text-sm opacity-70">
          This content is toggled by the button above, which lives outside <code>.collapsible</code> but inside <code>.collapsible-group</code>.
        </div>
      </div>
    </div>
  </div>
</div>