By leveraging native HTML5 <details> and <summary> elements, you can construct a fully functional, interactive accordion without a single line of JavaScript. This approach is inherently SEO-friendly and provides excellent out-of-the-box accessibility for keyboard users.

Demo

What are the features of this accordion?

It is built entirely with native HTML features and CSS, without using JavaScript. It is extremely lightweight, SEO-friendly, and accessible (e.g., keyboard support).

Can multiple items be opened at the same time?

By setting the name attribute to the same value (in this example, name=“faq”), it enables exclusive toggling where opening one automatically closes the others. If you want them to open simultaneously, simply remove the name attribute.

How is the animation implemented?

The icon rotation animation and content fade-in effect are implemented using CSS transition and @keyframes.

Code

<div class="accordion-container">
  <details class="accordion" name="faq">
    <summary class="accordion-summary">
      What are the features of this accordion?
      <span class="icon"></span>
    </summary>
    <div class="accordion-content">
      <p>It is built entirely with native HTML features and CSS, without using JavaScript. It is extremely lightweight, SEO-friendly, and accessible (e.g., keyboard support).</p>
    </div>
  </details>
  
  <details class="accordion" name="faq">
    <summary class="accordion-summary">
      Can multiple items be opened at the same time?
      <span class="icon"></span>
    </summary>
    <div class="accordion-content">
      <p>By setting the name attribute to the same value, exclusive toggling (opening one closes the others) is possible.</p>
    </div>
  </details>
</div>
/* Container styling */
.accordion-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

/* Accordion body */
.accordion {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background-color: #ffffff;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

/* Summary (heading) styling */
.accordion-summary {
  padding: 1.25rem 1.5rem;
  font-weight: 600;
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  list-style: none; /* Hide the default triangle marker */
  color: #1e293b;
  transition: background-color 0.2s ease;
  user-select: none;
}

/* Hide default triangle marker for Safari */
.accordion-summary::-webkit-details-marker {
  display: none;
}

.accordion-summary:hover {
  background-color: #f8fafc;
}

/* Underline for summary in open state */
.accordion[open] .accordion-summary {
  border-bottom: 1px solid #e2e8f0;
}

/* Toggle icon styling */
.icon {
  position: relative;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: 1rem;
}

/* Icon horizontal and vertical lines */
.icon::before,
.icon::after {
  content: '';
  position: absolute;
  background-color: #64748b;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 2px;
}

.icon::before {
  width: 16px;
  height: 2px;
}

.icon::after {
  width: 2px;
  height: 16px;
}

/* Animation when accordion opens (+ becomes -) */
.accordion[open] .icon::after {
  transform: rotate(90deg) scaleY(0);
}

.accordion[open] .icon::before {
  background-color: #3b82f6;
}

/* Content section styling */
.accordion-content {
  padding: 1.5rem;
  color: #475569;
  line-height: 1.6;
  animation: fadeDown 0.3s ease-out forwards;
}

.accordion-content p {
  margin: 0;
}

/* Soft fade-in animation */
@keyframes fadeDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

Implementation Points

  1. Native <details> & <summary> Elements: Utilizing semantic HTML automatically handles the complex open/close state logic and click event management entirely within the browser, rendering custom JavaScript unnecessary.
  2. Concealing Default Markers: Applying list-style: none; and targeting the pseudo-element ::-webkit-details-marker { display: none; } cleanly removes the browser’s default arrow icon, allowing us to implement a custom, highly styled toggle icon.
  3. Exclusive Accordion Behavior (The name Attribute): By assigning identical name attributes to adjacent <details> elements, you natively enforce an exclusive “accordion” toggle state—opening one section automatically collapses the others. (Note: This is a powerful, modern HTML specification).
  4. Sophisticated CSS Animations: A smooth content fade-in (@keyframes) and a dynamic icon morph from a plus (+) to a minus (-) (transition) are engineered purely with CSS, delivering a polished, high-end user experience.