Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create an HTML quine?

Per the title, is it possible to create a (non-trivial) quine in HTML?

My definition of an HTML quine:

A non-trivial HTML quine is one that is not null and uses at least one HTML tag, under the assumption that some string in an HTML file is rendered by a browser as plain text. An HTML quine is defined such that the output of the q.html as rendered by a standard browser is the contents of q.html itself.

(I'm open for any comments on this definition, I kind of hacked it up right now)

HTML is not turing-complete, therefore the fixed-point theorem cannot be applied to prove that it is indeed possible.

However, this does not necessarily mean an HTML quine is impossible. Or can it in fact be proven that an HTML quine is impossible?

like image 887
Yuval Adam Avatar asked Dec 06 '11 13:12

Yuval Adam


1 Answers

It's certainly not possible with "plain" HTML. Obviously it would be possible to do with JavaScript, but it's also possible with CSS:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>This is the title</title>
<style type="text/css"><![CDATA[ 
* {
  display:inline;
  white-space:pre;
}
html:last-child {
  white-space:normal;
}
html:before  {content:'<html xmlns="http://www.w3.org/1999/xhtml">';}
html:after   {content:'</html>';}
head:before  {content:'<head>';}
head:after   {content:'</head>';}
title:before {content:'<title>';}
title:after  {content:'</title>';}
style:before {content:'<style type="text/css"><![CDATA[';}
style:after  {content:']]\00003e</style>';}
body:before  {content:'<body/>';position:absolute;left:0;}
]]></style>
</head>
<body/>
</html>
like image 105
Thomas W Avatar answered Nov 15 '22 03:11

Thomas W