Quines are programs whose only purpose is to print out their own source code. It cannot be done by just reading the source code from the disk and printing it, of course; the compiled program must contain all information necessary to do that.

Several years ago I was quite interested in writing quines. Not for any particular reason; it was just a cool thing to do. (In case you didn't know I am a big nerd.)

Here are some I made recently. You only need to copy and paste them into a new file, then run the program, and the source code should be output again.


Recently I wondered what a HTML quine would look like, so I set out to make one. In the end I didn't make only one: I made four. Three of them are legitimate quines, the fourth one was made by cheating.

  • This is the most classic, straightforward approach to making a quine in any language: just store a copy of the source in some variables using some kind of encoding, then print out everything in both encoded and decoded form. The program is 216 characters long.
  • This one uses the JavaScript eval() statement. That makes things much easier, and is in the limit of what can be considered cheating :) It is 135 characters long.
  • Similar to the one before it but shorter, although I think it doesn't work in Internet Explorer. 130 characters long.
  • Using this last approach is cheating. It gets the contents of the page from the browser and prints them out. I'm just including it for completeness. It is 134 characters long.

If you can make shorter HTML/JavaScript quines, I'd like to know about it. I know that those are not the shortest possible HTML quines. The shortest one is an empty file, which displays as an empty webpage. But that is super-cheating! :)

More to follow... eventually