It's done via embedded HTML, which GitHub flavored markdown supports. I didn't know about the HTML details element, though. Pretty handy!
<details>
<summary>Click to expand</summary>
<div>Hidden until expanded, no JS or CSS required!</div>
</details>