Accordion Style for the Details Block (SCSS)
Styles the core Details block as a polished accordion with borders, a rotating plus icon and comfortable spacing, so FAQs look finished without a plugin.
Opens WPIDE on
Code
$border: rgba(0, 0, 0, 0.15);
$accent: #2271b1;
.wp-block-details {
margin: 0;
padding: 0;
border: 1px solid $border;
& + .wp-block-details {
border-top: 0;
}
summary {
position: relative;
padding: 1em 3em 1em 1.25em;
font-weight: 600;
list-style: none;
cursor: pointer;
&::-webkit-details-marker {
display: none;
}
&::after {
content: "+";
position: absolute;
top: 50%;
right: 1.25em;
font-size: 1.4em;
line-height: 1;
transform: translateY(-50%);
transition: transform 0.2s ease;
}
&:focus-visible {
outline: 2px solid $accent;
outline-offset: -2px;
}
}
&[open] summary::after {
transform: translateY(-50%) rotate(45deg);
}
> :not(summary) {
margin: 0;
padding: 0 1.25em 1em;
}
}
Notes
Consecutive Details blocks join into one accordion list.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.