Accordion component

Components

Structure
3
Styling
8px
PREVIEW

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

html
<div class="accordion">
  <div class="item">
    <input type="radio" id="acc-1" name="accordion" checked>
    <label for="acc-1">Section 1 Title</label>
    <div class="content">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
    </div>
  </div>
  <div class="item">
    <input type="radio" id="acc-2" name="accordion" >
    <label for="acc-2">Section 2 Title</label>
    <div class="content">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
    </div>
  </div>
  <div class="item">
    <input type="radio" id="acc-3" name="accordion" >
    <label for="acc-3">Section 3 Title</label>
    <div class="content">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
    </div>
  </div>
</div>
css
/* Pure CSS Accordion */
.accordion {
  max-width: 600px;
  margin: 0 auto;
  font-family: sans-serif;
}

.accordion .item {
  border-bottom: 1px solid #e2e8f0;
  background: #ffffff;
  color: #334155;
}

.accordion .item:first-child {
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}

.accordion .item:last-child {
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
  border-bottom: none;
}

.accordion input {
  display: none;
}

.accordion label {
  display: block;
  padding: 16px 20px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s;
  position: relative;
}

.accordion label:hover {
  background: rgba(0,0,0,0.02);
}

.accordion label::after {
  content: '+';
  position: absolute;
  right: 20px;
  transition: transform 0.3s;
}

.accordion input:checked + label {
  color: #3b82f6;
}

.accordion input:checked + label::after {
  transform: rotate(45deg);
}

.accordion .content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
  padding: 0 20px;
}

.accordion input:checked ~ .content {
  max-height: 200px; /* Adjust based on content */
}

GET MORE FROM THIS RESOURCE

Make collapsed sections easy to navigate

An accordion can reduce the visible length of optional information, such as common questions. It is less appropriate when everyone needs to read all of the content. Keep each section heading meaningful and implement expand/collapse behavior with buttons or native details elements.

Use the generator to establish the appearance, then adapt the exported markup and styles to your application. A preview demonstrates the visual treatment; it does not certify your final interaction. Check the implementation with real content, a narrow screen, and keyboard input before publishing.

Try the component in the code editor →