I made it work with a combination of previous answers and svg path like this while trying to represent a virtual filesystem. Hopefully useful for anyone else looking for this feature.
details>summary {
list-style-type: none;
cursor: pointer;
}
details>summary::before {
content: url('data:image/svg+xml;charset=UTF-8,<svg
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="rgb(255, 216, 104)" d="M20,6H10L8,4H2C0.9,4 0,4.9 0,6v12c0,1.1 0.9,2
2,2h16c1.1,0 2-0.9 2-2V8c0,-1.1 -0.9,-2 -2,-2zM2,6h4l2,2h10v10H2V6z"/></svg>');
}
details[open] > summary::before {
content: url('data:image/svg+xml;charset=UTF-8,<svg
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="rgb(255, 216, 104)" d="M20,4v4H4V4h16m0-2H4C2.89,2 2,2.89
2,4v16c0,1.11 0.89,2 2,2h16c1.11,0 2-0.89 2-2V8c0-1.11 -0.89-2 -2-2z"/></svg>');}
<details>
<summary>Click here</summary>
Some text!
</details>