<details> and <summary> elements to create accessible, no-JS accordions. Multiple accordions stack automatically with seamless borders.
Basic Accordion
Grouped Accordions
Use thename attribute to create radio-button-like behavior where only one item can be open at a time:
When using the
name attribute, opening one accordion automatically closes others in the same group.Features
No JavaScript
Uses native HTML
<details> and <summary> elements - works without any JavaScriptAuto-stacking
Adjacent accordions automatically merge borders for a seamless appearance
Smooth Animation
Animated chevron icon rotates when opening/closing with CSS transitions
Accessible
Semantic HTML with proper keyboard navigation and screen reader support
Styling Details
Container Styling
Container Styling
- Border: 1px solid with theme border color
- Border radius: medium (
var(--radius-medium)) - Adjacent accordions: merged borders and adjusted border radius
- Open state: border added below summary
Summary Styling
Summary Styling
- Display: flex with space-between layout
- Padding:
var(--space-4) - Font weight: medium
- Cursor: pointer
- Hover: muted background color
- Transition: smooth background color change
- Custom chevron icon (replaces default marker)
Content Styling
Content Styling
- Margin:
var(--space-4)on all sides - Applies to all children except
<summary>
Chevron Animation
Chevron Animation
- SVG chevron icon using CSS mask
- Rotates 180° when accordion opens
- Smooth transition with
var(--transition-fast) - Color: inherits from text color
Border Stacking
When multiple accordions are adjacent, they automatically stack with shared borders:- Adjacent accordions share a single border (using
margin-top: -1px) - First accordion: rounded top corners
- Middle accordions: square corners
- Last accordion: rounded bottom corners
Accessibility
- Native
<details>/<summary>provides built-in keyboard support - Space/Enter keys toggle accordion open/closed
- Screen readers announce expanded/collapsed state
- Focusable with keyboard navigation
- No ARIA required - semantic HTML handles everything
Browser Support
The accordion component uses modern CSS features:- Native
<details>element (widely supported) - CSS
:has()selector for border stacking - CSS
mask-imagefor the chevron icon
CSS Variables
--border- Border color--radius-medium- Border radius--space-2,--space-4- Spacing--font-medium- Font weight--muted- Hover background color--transition-fast- Animation speed