The three most desirable features for code blocks on web pages, in my opinion, are syntax highlighting, code folding, and the copy button. Syntax highlighting is way beyond my capability to implement, but the rest two are simple enough. Yesterday I blogged about folding code. Today let’s talk about the copy button.

The Clipboard API

To implement a copy button, you need to know the Clipboard API in JavaScript (in particular, the …