384

CSS isn't, insofar as I know, Turing complete. But my knowledge of CSS is very limited.

  • Is CSS Turing complete?
  • Are any of the existing draft or committees considering language features that might enable Turing completeness if it isn't right now?
devios1
  • 36,899
  • 45
  • 162
  • 260
Adam Davis
  • 91,931
  • 60
  • 264
  • 330
  • 40
    It's already been done, if you use ie6. They're called CSS expressions, and consensus is they are horribly broken and dangerous. JS embedded in CSS... – kibibu Mar 23 '10 at 02:23
  • 19
    @Kibibu - Yikes! Please erase that idea from my brain before it folds on itself! – DVK Mar 23 '10 at 02:25
  • How could CSS _possibly_ be Turing-complete? – SLaks Mar 23 '10 at 02:29
  • 1
    @DVK: you could actually do some cool things with them - particularly with regards to resolution independent layout - that are still tricky or quirky in CSS without resorting to tables. I think if they'd limited it to be strictly a declarative expression language with no side-effects instead of allowing full access to the script engine it would have been better received (and maybe also if webkit had come up with it first) – kibibu Mar 23 '10 at 03:20
  • 10
    @SLaks: Don't underestimate the power of HTML5/CSS3 :) – Niklas B. Feb 28 '12 at 17:10
  • So embedding a Turing-complete language in XYZZY which isn't TC without makes XYZZY TC… logic, this ain't. – Jürgen A. Erhard Jul 27 '23 at 00:53

7 Answers7

466

You can encode Rule 110 in CSS3, so it's Turing-complete so long as you consider an appropriate accompanying HTML file and user interactions to be part of the “execution” of CSS. A pretty good implementation is available, and another implementation is included here:

body {
    -webkit-animation: bugfix infinite 1s;
    margin: 0.5em 1em;
}
@-webkit-keyframes bugfix { from { padding: 0; } to { padding: 0; } }

/*
 * 111 110 101 100 011 010 001 000
 *  0   1   1   0   1   1   1   0
 */

body > input {
    -webkit-appearance: none;
    display: block;
    float: left;
    border-right: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
    padding: 0px 3px;
    margin: 0;
    font-family: Consolas, "Courier New", monospace;
    font-size: 7pt;
}
body > input::before {
    content: "0";
}

p {
    font-family: Verdana, sans-serif;
    font-size: 9pt;
    margin-bottom: 0.5em;
}

body > input:nth-of-type(-n+30) { border-top: 1px solid #ddd; }
body > input:nth-of-type(30n+1) { border-left: 1px solid #ddd; clear: left; }

body > input::before { content: "0"; }

body > input:checked::before { content: "1"; }
body > input:checked { background: #afa !important; }


input:not(:checked) +
        *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
        input::before {
    content: "1";
}
input:not(:checked) +
        *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
        input {
    background: #fa0;
}


input:checked +
        *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
        input::before {
    content: "1";
}
input:checked +
        *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
        input {
    background: #fa0;
}


input:checked +
        *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
        input::before {
    content: "1";
}
input:checked +
        *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
        input {
    background: #fa0;
}

input:checked + input:checked + input:checked +
        *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
        input::before {
    content: "0";
}
input:checked + input:checked + input:checked +
        *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
        input {
    background: #fff;
}

input:not(:checked) + input:not(:checked) + input:not(:checked) +
        *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
        input::before {
    content: "0";
}
input:not(:checked) + input:not(:checked) + input:not(:checked) +
        *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
        input {
    background: #fff;
}

body > input:nth-child(30n) { display: none !important; }
body > input:nth-child(30n) + label { display: none !important; }
<p><a href="http://en.wikipedia.org/wiki/Rule_110">Rule 110</a> in (webkit) CSS, proving Turing-completeness.</p>

<!-- A total of 900 checkboxes required -->
<input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/><input type="checkbox"/>
Solomon Ucko
  • 5,724
  • 3
  • 24
  • 45
Jakob
  • 3,570
  • 3
  • 36
  • 49
  • 13
    The formal definition (simplest) of Turing Machine is simply a tuple of states set, symbol set, initial state, accepting states set and a transition function. There is no crank in it. By computation we mean somebody needs to apply the transition function faithfully on the tape which is exactly like the clicking in this case. More formally, a model of computation can be viewed as a set of rules somebody needs to follow to do the computation. In that sense, I think CSS is Turing-Complete. – Shuhao Tan Jun 11 '18 at 21:32
  • 3
    This snippet doesn't appear to work (Firefox 61). I see a grid of empty checkboxes - nothing happens if you check them. – OrangeDog Sep 03 '18 at 11:38
  • 10
    @John "CSS is turing complete" makes me uneasy, but I have no problem with "CSS is as turing complete as [a couple of rocks on the beach](https://xkcd.com/505/)". Would the latter statement be correct? – Raphael Schmitz Mar 01 '19 at 12:40
  • 8
    @R.Schmitz no, in that case the human is choosing where to put the rocks, so it is the combined system of human+rocks that is turing complete. In the CSS example above, the tab+space keypresses is a simple repeating process, similar to say, a feedback circuit. So if C++ is turing complete using computer hardware to execute instructions, then it's not a stretch to say CSS is turing complete using repeating keypresses to execute instructions – woojoo666 Mar 05 '19 at 02:21
  • Here is a CodePen of Rule 110 using the same solution, plus annotations and some Sass to help DRY things out: https://codepen.io/laras126/pen/OYvGZj I wrote an accompanying blog post explaining the concepts here: https://notlaura.com/is-css-turing-complete/ – notlaura Jun 16 '19 at 12:57
  • A pile of rocks *requires* a human to interpret their placement in a complex way to be an automata (TC or otherwise). A hard drive *requires* a computer to interpret programs stored on it. A modern computer (CPU+Motherboard+RAM+PSU) similarly "requires" an applied 60Hz voltage, yet we'd call it turing-complete (and *not* the rocks nor the HDD, except as part of an obscure philosophical argument.) **Perhaps this is a useful intuition pump.** (My "opinion" is that it's reasonable to regard a mere space-tab cycle as more like an AC power source, but I'm not sure how to resolve ambiguity there.) – JamesTheAwesomeDude Oct 23 '19 at 17:46
  • 5
    Say that _“[CSS] is Turing-complete so long as you consider an appropriate accompanying HTML file and user interactions to be part of the “execution” of CSS”_ more or less sounds like _“it's Turing-complete so long as you consider it to mean it can display a red border”._ – Andrea Lazzarotto Dec 18 '19 at 22:53
  • There are improvements on this method recently: https://accodeing.com/blog/2015/css3-proven-to-be-turing-complete – polkovnikov.ph Feb 23 '21 at 05:42
  • If user input is unconditionally required it can also be seen as not turing complete. – Blackbam May 04 '21 at 22:38
  • 1
    @AndreaLazzarotto and a computer is turing-complete as long as it's got electricity. It's not like an accompanying HTML file is "cheating" in *any* sense of the word, since CSS is supposed to ride alongside HTML anyway. – JamesTheAwesomeDude May 21 '21 at 16:39
  • 1
    @Blackbam The thing is, the "input" it requires is nothing more than a monotonic beating on the keyboard to push the machine along; a PC requires _much_ more complex "inputs" to run, since a switching power supply has to adapt to the load. So if requiring "input" for power makes something not-turing-complete, then can anything be so? – JamesTheAwesomeDude May 21 '21 at 16:41
  • 2
    Unfortunately, this most highly voted answer is not accurate. All implementations is CSS only encode *ONE STEP* of Rule 110 (or any other algorithm). They are not capable of advancing to the next step of computation which is an essential part of Turing completeness. – Yuriy Ershov Jul 21 '21 at 11:08
  • 1
    A pen and a piece of paper is Turing-complete so long as you consider user interactions to be part of the “execution” of pen and paper. – Hakanai Aug 13 '22 at 09:18
116

One aspect of Turing completeness is the halting problem.

This means that, if CSS is Turing complete, then there's no general algorithm for determining whether a CSS program will finish running or loop forever.

But we can derive such an algorithm for CSS! Here it is:

  • If the stylesheet doesn't declare any animations, then it will halt.

  • If it does have animations, then:

    • If any animation-iteration-count is infinite, and the containing selector is matched in the HTML, then it will not halt.

    • Otherwise, it will halt.

That's it. Since we just solved the halting problem for CSS, it follows that CSS is not Turing complete.

(Other people have mentioned IE 6, which allows for embedding arbitrary JavaScript expressions in CSS; that will obviously add Turing completeness. But that feature is non-standard, and nobody in their right mind uses it anyway.)


Daniel Wagner brought up a point that I missed in the original answer. He notes that while I've covered animations, other parts of the style engine such as selector matching or layout can lead to Turing completeness as well. While it's difficult to make a formal argument about these, I'll try to outline why Turing completeness is still unlikely to happen.

First: Turing complete languages have some way of feeding data back into itself, whether it be through recursion or looping. But the design of the CSS language is hostile to this feedback:

  • @media queries can only check properties of the browser itself, such as viewport size or pixel resolution. These properties can change via user interaction or JavaScript code (e.g. resizing the browser window), but not through CSS alone.

  • ::before and ::after pseudo-elements are not considered part of the DOM, and cannot be matched in any other way.

  • Selector combinators can only inspect elements above and before the current element, so they cannot be used to create dependency cycles.

  • It's possible to shift an element away when you hover over it, but the position only updates when you move the mouse.

That should be enough to convince you that selector matching, on its own, cannot be Turing complete. But what about layout?

The modern CSS layout algorithm is very complex, with features such as Flexbox and Grid muddying the waters. But even if it were possible to trigger an infinite loop with layout, it would be hard to leverage this to perform useful computation. That's because CSS selectors inspect only the internal structure of the DOM, not how these elements are laid out on the screen. So any Turing completeness proof using the layout system must depend on layout alone.

Finally – and this is perhaps the most important reason – browser vendors have an interest in keeping CSS not Turing complete. By restricting the language, vendors allow for clever optimizations that make the web faster for everyone. Moreover, Google dedicates a whole server farm to searching for bugs in Chrome. If there were a way to write an infinite loop using CSS, then they probably would have found it already

Lambda Fairy
  • 13,814
  • 7
  • 42
  • 68
  • 8
    When people say "CSS is turing complete" they mean "CSS, which supports animations is Turing Complete". You can restrict programming languages and conclude they are not Turing Complete using your logic, but you would have to specify the restrictions. – felipecrv Aug 13 '15 at 12:41
  • @philix can you elaborate? I did account for animations in my answer. – Lambda Fairy Aug 14 '15 at 22:50
  • I have to disagree, as per the definition of the [halting problem](https://en.wikipedia.org/wiki/Halting_problem#Representation_as_a_set) and using animations, as you say, one could write a media query that have an animation, therefore it will run infinitely if this media query is matched, witch can only be decided running the CSS code. So the halting problem is not sufficient to tell if CSS is turing complete. – madcampos Sep 12 '15 at 04:28
  • @madcampos I think "... and the containing selector is matched in the HTML" covers that already. Besides, the halting problem lets you inspect the input -- the page you linked says exactly that. The only condition is that my algorithm works on all programs and inputs, which it does. – Lambda Fairy Sep 12 '15 at 09:33
  • 53
    I think this answer is using a funny definition of "halt" -- certainly not the one I would want if I were asking the question, at least. You seem to use "halt" to mean "there is a time at which the computed properties for each element stop changing"; but I would want "halt" to mean "the algorithm which transforms declarative CSS into the computed properties of all elements finishes running". With the latter definition, it seems there needs to be significantly more argument than just "there are no animations". – Daniel Wagner Oct 06 '15 at 03:23
  • 19
    Your logic is backwards here. Turing completeness implies that halting is undecidable doesn't mean that halting is undecidable implies Turing completeness. – asmeurer Jan 13 '17 at 18:14
  • 4
    -1'd. This isn't a proper proof, and misinterprets the idea of being turing complete and the set of undecidable problems for a TM (turing machine). *IF* a machine can solve the halting problem (determine if a machine will halt), then it will be *more* powerful than a TM, and therefore also be able to solve any problem a TM can solve. Even if the proof was correct, you've proved that not only is CSS turing complete, but it more powerful than a turing machine (which is not true). I'd advise editing with a disclaimer to not mislead any computation theory students. – Mike Shi Jan 21 '17 at 01:06
  • 5
    @LambdaFairy what is the halting problem *for CSS*? I don't believe such a thing exists. The halting problem is only relevant to machines. The most powerful computational model we have today are Turing Machines. Your computer is as powerful as a Turing Machine (w/o infinite memory). CSS alone can not be defined as a machine. Perhaps you can define the CSS engine of a browser as a machine, but even then it can only be as powerful as a TM. The statement "halting problem *for CSS*" just simply doesn't make any sense, unless CSS has become a new automaton in Chomsky's hierarchy. – Mike Shi Jan 21 '17 at 21:33
  • 1
    @LambdaFairy you should take a look at Chapter 5.1 in Sipser's Intro to the Theory of Computation 3rd Ed. to review TMs and the halting problem. – Mike Shi Jan 21 '17 at 21:39
  • 8
    @LambdaFairy You're misunderstanding what a proof of turing incompleteness would look like. We know that the halting problem is undecidable by a TM. The original proof seems to make the claim because CSS can solve the halting problem it is not turing complete. If CSS could truly solve the halting problem, then CSS is stronger than a Turing Machine because it could compute something a TM can't. We know (by the Church-Turing Thesis), that a machine can't be built that's stronger than a TM/The Lambda Calculus. Therefore, this is a contradiction, and your original statement isn't correct. – Isaac Diamond Jan 22 '17 at 05:03
  • Feedback is not required. Suppose I write a program that on every iteration Processes half of my RAM and writes the updated results to the other half. It would then process the updated half of RAM and write the results to the first half again, and so on and so forth. Because turing completeness does not define a memory limit, you could just as easily just copy the entire memory every time to a larger and larger "address". Suppose it did this for every "instruction". At no point does it need to read earlier data. There is always a fresh copy of everything. – Cedric Mamo May 10 '19 at 13:32
  • continued. So if as you say, you can only access elements above and before, you could just have a table, and any unchanged values are copied to the row below (or rather, taken from the cell above). – Cedric Mamo May 10 '19 at 13:37
  • 1
    @LambdaFairy but "decidable implies not Turing complete" does not imply "not decidable implies Turing complete". That is your logic error. – OrangeDog May 20 '19 at 12:59
  • @asmeurer I think you misunderstood the answer Consider "Turing completeness implies that halting is undecidable". The contrapositive of this is "Halting being decidable implies that it's Turing-incomplete", which is what the answer said, and it's equiv to the first statement. – éclairevoyant Jun 26 '22 at 20:13
33

As per this article, it's not. The article also argues that it's not a good idea to make it one.

To quote from one of the comments:

So, I do not believe that CSS is turing complete. There is no capability to define a function in CSS. In order for a system to be turing-complete it has to be possible to write an interpreter: a function that interprets expressions that denote programs to execute. CSS has no variables that are directly accessible to the user; so you cannot even model the structure that represents the program to be interpreted in CSS.

DVK
  • 126,886
  • 32
  • 213
  • 327
  • 4
    CSS isn't executable in any way. The person who wrote the quoted comment doesn't seem to understand that. :-\ – Ryan Prior Mar 23 '10 at 03:01
  • 42
    CSS is a set of instructions to a processor (layout engine). What's so not "executable" about it? – DVK Mar 23 '10 at 03:26
  • 64
    Turing-completeness is not just about if you can write programs the way you want or a belief. It is a mathematical property about calculability. So you cannot believe or not that CSS is Turing-complete, you need a proof. In this case, because of the rule 110, CSS is Turing-complete. – Mikaël Mayer Jun 14 '13 at 09:30
  • 17
    @MikaëlMayer - as noted in many comments in the "110" answer, that requires user to perform an action. If user actions are requred, CSS without the user is NOT Turing complete – DVK May 02 '14 at 22:07
  • Some interesting trivia: Mozilla has a RegEx selector for CSS based on the URL. This isn't much, but you can now create single-pass programs based on RegEx. One thing RegEx does well, is [primality testing](http://codegolf.stackexchange.com/a/68049/42643) :). – turbo Aug 09 '16 at 07:55
  • 8
    @DVK the repeating keypresses required by the CSS 110 example are not quite a user "action", they can be performed by a repeating digital circuit. Actual turing machines require some sort of electrical hardware to drive execution, so I don't see how this is any different – woojoo666 Mar 05 '19 at 02:22
6

The fundamental issue here is that any machine written in HTML+CSS cannot evaluate infinitely many steps (i.e there can be no "real" recursion) unless the code is infinitely long. And the question will this machine reach configuration H in n steps or less is always answerable if n is finite.

  • 2
    I don't see where in the Turing Machine requirements the ability to process infinite loops is specified. Your second point doesn't appear to be valid. While Turing used his Turing Machine to prove issues of computability, these rules, like the halting problem, do not determine whether a machine is a turing machine or not. If the Turing Machine included these hypothesis as requirements he couldn't have used the turing machine to prove them. – Adam Davis Jun 14 '16 at 17:26
  • 6
    @AdamDavis It's a totally valid argument: if an algorithm exists that solves the halting problem for a Turing-complete formalism, that's equivalent to solving the halting problem in general. Of course, this has been proven impossible, which means that if the halting problem can be solved for a given formalism, then that formalism must *not* be Turing-complete. Therefore, all formalisms that can only evaluate a finite number of steps cannot be Turing-complete, CSS included. – 00dani Oct 07 '16 at 10:22
  • 2
    @AdamDavis If CSS cannot express infinite loops, then its answer to the Halting Problem is trivial -- the program will always halt. Since all Turing complete languages have an undecidable Halting Problem, this eliminates CSS from being Turing complete. – Lambda Fairy Jan 14 '17 at 01:09
  • @LambdaFairy per the discussion under your answer this depends on the assertion that a language cannot be Turing complete if the halting problem is solvable on it. I understand the concept and the logic behind the assertion. I'm not sold on the "if A then B" means "if B then A" assertion, but I understand why you continue to promote that as proof that it isn't a Turing machine. – Adam Davis Jan 14 '17 at 03:21
  • 4
    It's *not* if B then A! It's if **not B** then **not A**! The former is [affirming the consequent](https://en.wikipedia.org/wiki/Affirming_the_consequent), which you correctly point out is wrong. The latter, [argument by contrapositive](https://en.wikipedia.org/wiki/Proof_by_contrapositive), is what I use and is valid. Note the careful use of negation in my last comment -- I constructed it specifically to avoid that fallacy. – Lambda Fairy Jan 14 '17 at 07:04
  • looking at a HTML+CSS page and saying it halts is like performing one step of a Turing machine and saying it halts. CSS defines rules that transform the DOM, just like a Turing machine defines rules that transform the tape. Just like a Rule 110 automata defines rules that transform the cells. Thus, since CSS can express a rule 110 automata, then it is turing complete – woojoo666 Mar 25 '19 at 11:11
  • 2
    @woojoo666 No. Having being able to transform state according to a set of rules is not the same as being Turing complete. Nothing that can only for a finite number of steps can ever be turing complete. If the set of transformations rules can only be applied a finite number of times the question "Will the system ever reach state `H`?" is always decidable and it is thus not Turing complete. An implementation of a cellular automaton that can only do a finite number of iterations can never be turing complete. – Henrik Sommerland Mar 25 '19 at 13:18
  • @HenrikSommerland but the Rule 110 automata implemented in HTML+CSS (in the top answer) is capable of infinite iterations. And before you say "user-interaction is not part of CSS", that's not what I'm saying. User-interaction is just driving the state transition, just like an electronic circuit would drive the state transition of a turing machine. But that circuit need not be included in the definition of a turing machine, just like user-interaction need not be included in the definition of CSS for CSS to be turing complete – woojoo666 Mar 26 '19 at 02:48
  • A computer is technically not turing complete because memory would eventually run out. It's just that a lot of problems happen to fit in the memory we have. Being truly turing complete requires infinite memory. Wouldn't just adding more rows to the table be the equivalent of adding more RAM? I.e. it would just mean CSS has more "memory" to work with. The point is, given a table of infinite size (infinite memory), CSS could compute anything. – Cedric Mamo May 10 '19 at 13:40
  • No it is. You could always add more memory. And one does not talk about a 'computer' being turing compute, a lanugage is turing complete. the language C is turing complete regardless of any fact about anything related to actual computers. the thing that makes your computer turingcomplete is not the physical computer it is the ISA. And it has nothing to do with memory, just that the number of configurations a machine can be in is unbounded. – Henrik Sommerland May 13 '19 at 13:42
  • In CSS/HTML i can define a table of one size (which may be arbitrary large) but then when I execute the machine the number of states the system can be in is limited to the size of the table. Whilst a C for example can request more memory at any time (and we do not care about the real world when discussing automatons :P ) so we will always have more state-space available as the machine executes. @CedricMamo The key takeaway is that reality does not matter. It is the fact that CSS/HTML has a fixed state-space. If you cold add table rows dynamically/"in the browser" the story would be different. – Henrik Sommerland May 13 '19 at 13:45
  • @CedricMamo Btw, if there, somewhere in the C specifications (not implementation) where to be a limit on the size of the address space, C would not be Turing complete. One would need to add some form of external storage of arbitrary size to make it Turing complete. – Henrik Sommerland May 13 '19 at 13:54
  • But there isn't. In fact it's configurable after compilation by modifying the exe if you want. (the only way to actually do it for a c# application, actually) ). Doesn't really have anything to do with C itself. Nothing you could build can ever be turing complete technically, given that infinite memory is a requirement. – Cedric Mamo May 13 '19 at 17:20
  • as for the size of the table argument, substitute the word "table" with the word "RAM" and suddenly it applies to *any* computer system anywhere in the world. How do you get around the limitation in a PC? You install more RAM. How do you get around it in CSS? You make a bigger table. – Cedric Mamo May 13 '19 at 17:22
  • I misread your comment somehow (was a bit tired at the time) and read that as "Stack space" instead of address space. But I don't think the C spec defines the size of the address space. – Cedric Mamo May 14 '19 at 14:10
  • Yes no physical computer could ever conceivably be turing complete. But there s no real point talking about turingcompletness of physical things. The notion of turingcompletness is a pruerly academic one relating to formallanguages, automaton theory, proof theory and a bunch of other stuff. Only abstract systems can be turing complete. But the problem with CSS/HTML is that it is always fixed by the language. You could make it arbitrary large but only before execution. If you were, to in the description of the system, add a clause about modifying the html dynamically things are different. – Henrik Sommerland May 15 '19 at 10:35
  • @CedricMamo Im actually considering making a Youtube video about this. It is a notion that confuses a lot of people. – Henrik Sommerland May 15 '19 at 10:37
  • I am not confused at all. When I mention turing completeness, I know that I'm referring to the computational model, and not the physical hardware that implements it. That's why C#, C++, brainfuck and, yes, also CSS are turing complete. The languages are turing complete. Their implementations, by definition, cannot ever be. When I discuss turing completeness I do so outside of the context of any of their implementations. – Cedric Mamo May 15 '19 at 14:11
  • 2
    “and, yes, also CSS are turing complete” _[citation needed]_ – Andrea Lazzarotto Dec 18 '19 at 23:02
  • The boundedness issue seems to be brought up a lot when discussing Turing machines. One fundamental principle that is very important is that *any halting turing machine uses a finite amount of memory*. What this means is that for any useful computation, it is possible to build a computer with enough RAM/table space/etc. to perform it. So we don't need an *infinite* table, we need an *unbounded* one. And since there is no HTML size cap, HTML5+CSS3 is turing complete. – Circuit Craft Apr 16 '20 at 21:45
  • @CircuitCraft Even tho there is no size cap to an HTML+CSS3 program there is for any given such program only a finite amount of states that the evaluated page can be in. Thus it will not be truing complete. In contrast, a TM implemented in C code will be finite but there is no restriction to the number of states that it can take during evaluation. – Henrik Sommerland Apr 19 '20 at 15:11
  • @HenrimSommerland I've actually seen this argument applied to C as well. Pointers have a bounded size, so technically a given execution has a finite number of states (well, a stack too, so it's a pushdown automaton). But C is obviously Turing complete (as you said in your answer) because there is no limit to that bound. – Circuit Craft Apr 19 '20 at 16:08
  • @CircuitCraft There is no size restriction on a pointer in the C99 specification so there is no limit during execution. The issue with having the evaluation space be finite is that i can build a machine that enumerates all the possible states (both the "memory" and internal states), runs your machine in it, keeps track of all the visited states and your machine will always either halt or enter into an state in which it has already been and thus be in a loop. So if you give me a program with a finite state space I can answer if it halts or not, your program cannot be Turing Complete. – Henrik Sommerland Apr 20 '20 at 18:56
  • @HenrikSommerland If you want to run a really memory-intensive program on your computer, and you don't have the memory for it, you go and buy some more. Equivalently, f you don't have enough memory for the program you are running in CSS, you just increase the size of the HTML file, and add more rows and columns. There is no difference in the abstract computational model. My point was that the CSS works for arbitrarily sized HTML files. When I referenced C, I meant that at runtime, the pointer size is bounded, just like the HTML file is bounded *at runtime*. We can always make a bigger file. – Circuit Craft May 20 '20 at 21:24
6

This answer is not accurate because it mix description of UTM and UTM itself (Universal Turing Machine).

We have good answer but from different perspective and it do not show directly flaws in current top answer.


First of all we can agree that human can work as UTM. This mean if we do

CSS + Human == UTM

Then CSS part is useless because all work can be done by Human who will do UTM part. Act of clicking can be UTM, because you do not click at random but only in specific places.

Instead of CSS I could use this text (Rule 110):

000 -> 0
001 -> 1
010 -> 1
011 -> 1
100 -> 0
101 -> 1
110 -> 1
111 -> 0

To guide my actions and result will be same. This mean this text UTM? No this is only input (description) that other UTM (human or computer) can read and run. Clicking is enough to run any UTM.


Critical part that CSS lack is ability to change of it own state in arbitrary way, if CSS could generate clicks then it would be UTM. Argument that your clicks are "crank" for CSS is not accurate because real "crank" for CSS is Layout Engine that run it and it should be enough to prove that CSS is UTM.

Yankes
  • 1,958
  • 19
  • 20
  • Rule 110 is a UTM. Your text is a (probably slightly insufficient) description of Rule 110, so yes that text is a (representation of a) UTM. – OrangeDog Sep 19 '18 at 09:10
  • "If CSS could generate clicks" I use a lot of AVR microcontrollers in my projects. You can either use an internal clock, which is limited to 8MHz. Alternatively, you could connect an external crystal and go up to 20MHz. Alternatively I could also just supply a completely external clock so it's not even cpu hardware that's actually driving the crystal. Meaning that I can actually wire up a switch and a piece of circuit to debounce it, and quite literally use that as a clock with me pressing the button. Does that mean it stops being turing complete if I do that? – Cedric Mamo May 10 '19 at 13:44
  • Hit the comment size limit, continued: It would just run at a different speed. Its speed would just be determined by how quickly I can repeatedly tap a button. But my finger isn't doing any computation at all. So no, turing completeness is not affected by what or who is driving the clock. In the case of CSS, the "hardware" does not provide a clock for you, you just need to supply your own. Whether it's you, or a piece of JS code to repeatedly send button press events doesn't really matter with regards to what it can compute. – Cedric Mamo May 10 '19 at 13:50
  • 2
    @CedricMamo But your clicks change state, and you need click only correct places other wise it would not work. Look exactly on http://eli.fox-epste.in/rule110-full.html I can click ANY cell, if CSS is disabled I still click correct cells and have UTM. If all you do would be clicking one button "next" then indeed CSS would be UTM, but to have something like that you would need have some JS that is call per button click, and as we know JS IS UTM. For CSS you need have something that will correctly interpreted result and update state. – Yankes May 11 '19 at 14:46
  • well the one inplementation I tried required *only* pressing tab, space, tab, space, tab, space, etc. So no, I already saw one where user decisions did not need to be made. – Cedric Mamo May 11 '19 at 18:31
  • 1
    @CedricMamo any link to it? Right now I look on couple of examples from there but it do not work for me. Overall if I understand correctly CSS change visibility of some check boxes and you use tabs to navigate to next one, and here we have again hidden UTM that is not CSS, because when you tab you ask browser to calculate next valid position to navigate, and to od thins it do LOT of complex code, this use CSS but its lot more. This mean you prove that your browser is UTM not CSS. – Yankes May 12 '19 at 01:13
  • It's the one you linked to. Set up the top row, then click the word "click me". Then it must have a slight bug or something, click the first cell of row 2 twice (to flip it once and back to its original state) and then just tab space – Cedric Mamo May 12 '19 at 05:18
  • and the browser moving the focus to the next focusable button doesn't take away from the fact that it's CSS deciding what's focusable or not. The browser isn't doing any decisions. This is like saying a physical turing machine is not turing complete because it's an electric motor that moves the tape left/right, not the part that makes a decision whether it should be moved to the left or right. – Cedric Mamo May 12 '19 at 05:23
  • @CedricMamo "Next button" is not "next cpu step", theoretically "Tab" need visit and examine every HTML element to check if is correct stop place. Overall you prove that TAB+SPACE is Turing complete, not CSS. You could probably drop CSS and replace it with something else and you sill could have UTM. Or looking from another perspective, yes, CSS decide what next step is, but this is only thing that can do and its not enough to to be UTM. It have only readonly access to page. If it can change something, it can't read it back. In case of CPU, you do not need read state, only send one signal. – Yankes May 13 '19 at 18:55
  • 1
    In a cpu when one instruction ends it leaves itself in such a state such that when the clock goes high again, electrons flow and the right transistors happen to switch in the right combinations. It's not the cpu (the computational model) that actually allows the computation to happen. It's physics! If electrons didn't follow this path instead of that the cpu wouldn't be able to set things up for the next step. The browser is the hardware CSS runs on. I don't know what the problem is. Css sets up a state such that according to the "physics" of its world it lives in leads to the next state. – Cedric Mamo May 14 '19 at 02:03
  • @CedricMamo If CSS is UTM then TXT file is UTM too. Text file can contain C++, C# but even CSS code. You only need correct "hardware". Now what is not UTM then? Could you show me things that can do some calculation and is not UTM? – Yankes May 14 '19 at 17:53
  • 1
    It's not c#, the code written in the text file, that's turing complete. It's not the text file that is turing complete. It's the set of rules described by the c# spec that are turing complete. Whether they're written in a text file, carved in stone, or simply just remembered in their entirety, it's those rules that are turing complete. Not the C# compiler, or any of the generated code. You seem to have a fundamental misunderstanding of what the phrase "computational model" means. The rules imposed by the CSS spec on how that text is interpreted, are turing complete. – Cedric Mamo May 15 '19 at 10:30
  • @CedricMamo Quite opposite, *IF* CSS is UTM *THEN* TXT file *IS* UTM too. I use your logic to prove this. I say that CSS IS NOT UTM therefore I can't prove that TXT is UTM (because is not). My whole point is that CSS in its own definition lack things need to be UTM. If I'm wrong show me where in CSS you have recursion in its definition? This is exactly same case with SQL for long time it was not UTM because it lack it, but with some new addtions it became UTM – Yankes May 15 '19 at 23:39
  • @CedricMamo It have loops that can do similar functionality as recursion (infinite calltail is loop and loop + buffer can simulate recursion). My point is that CSS do not have any of them in its definition. – Yankes May 16 '19 at 20:25
  • 1
    Rule 110 is proven turing complete. Cellular automata do not suppost looping. A cellular automaton only defines a set of state transitions. From the current to the next state. Looping is not a requirement. Conway'a game of life is also turing complete. It too does not support looping, but just a set of state transitions. – Cedric Mamo May 17 '19 at 02:33
  • 1
    @CedricMamo But Cellular automata have in its own definition a loop, when state transition is done then its run again, and again etc. If we remove it and leave only this state transition then this automata will not be UTM any more. This will be exactly same situation as CSS. We can define two steps in CA, `R` - read state, and `W` - write state, normal CA do infinite sequence `RWRWRWRW...` in case of CSS we have only `R`, and we do not have `W` because it modify things that it can't read, only if we add `B` - browser action then we could have `RBRBRBR...` but then `BBBBBB` is on its own UTM. – Yankes May 17 '19 at 18:20
  • 1
    No, they don't. They define a state transition and that's it. That's all it takes to make it a UTM. It doesn't specify how it should be done, whether you do it on a computer or a piece of paper, if you follow those rules to the letter, you would be able to compute anything. In CSS you can define those exact same state transitions. Doesn't matter how they're stored. Doesn't matter how they're accessed. Doesn't matter who runs the clock. The important thing is that CSS allows those rules to be specified. And that's what makes it a UTM. Anything else is just extra criteria you and only you added. – Cedric Mamo May 22 '19 at 20:55
  • @CedricMamo from Wiki: ` For each cell, a set of cells called its neighborhood is defined relative to the specified cell. An initial state (time t = 0) is selected by assigning a state for each cell. A new generation is created (advancing t by 1), according to some fixed rule (generally, a mathematical function)` This part: `advancing t`, in general CA you have defined that this transition rule is applied infinite times (for each time moment). could you show mi something like this in CSS definition? – Yankes May 24 '19 at 17:51
  • 1
    yoi define the initial state by setting the cells. The CSS specifies the transitions to make to turn the current generation into the next one. In an automaton, it doesn't define how to advance t. In fact a cellular automaton can't advance t. Whether it's a program or just you working out the next gen on paper, applying the rules to the generation, makes the process turing complete. Advancing t means calculating the next generation from the current one. CSS does just that. How to advance t? However the hell you want. Because t+1 is just a way to mathematically say "the next gen" not rly a time – Cedric Mamo May 25 '19 at 03:19
  • Ok, if advanceing time is not part of UTM then nearly everything is UTM. Old sql: `int i = 1; while(i) i =CallSql(sql, i);`, C preprocesor (you feed result back to it again), any calculator is UTM. If you can loop to any thing then it can become UTM. – Yankes May 25 '19 at 10:53
  • @CedricMamo Another thing, could you pull this CSS as UTM in `html2pdf` tool that have 100% CSS support? – Yankes May 25 '19 at 11:19
  • could you have a cellular automaton? – Cedric Mamo May 25 '19 at 22:08
  • @CedricMamo You do not answer to my question, CSS can be "UTM" as part browser that have already UTM capabilities. Another thing is import difference to CA, CSS is "function" from html to "pixels" and CA is "function" form cells to cells. CSS can't transform its output again because its different thing that is input. CA do not have this problem. – Yankes May 26 '19 at 00:06
  • ok, I'll answer. No I can't. Could you put a cellular automaton in there? And please answer this question and not a different one like you just did. Because every time you move the goalposts. Regardless of whether you know what turing completeness or not, CSS is turing complete. And please, css does not convert anything to pixels, it workes purely on the dom. The browser engine is what renders the dom. And after all, turing completeness does not specify what type of function it is anyway.This is just getting cringeworthy. It's ok to not know. It's downright stupid to not want to learn. I'm out – Cedric Mamo May 26 '19 at 06:16
  • And please go learn what turing completeness is and stop inventing more rules to justify why css isn't turing complete. You keep adding a bunch of requirements that just aren't there. So yeah CSS isn't turing complete according to what convoluted idea of turing completeness you have. But it IS turing complete according to what being turing complete actually requires – Cedric Mamo May 26 '19 at 06:23
  • @CedricMamo "pixels" in quotes, CSS define looks of page, this could be sum up simply as "pixels", it can't read it back anyhow. And I do not move goalposts, only more precisely point out what CSS lack to be UTM. Its do not have on its own way to do more than "one step" and result of its working is not input of it. If you could change this then CSS will be UTM. This is mathematic its demand precision. To make CSS UTM you need add things that are outside definition of CSS, this is why I give you exactly case where we have CSS in other environment and it cant pull UTM ergo CSS is not UTM. – Yankes May 26 '19 at 23:01
  • 1
    Again, first of all can can read the DOM, It defines a set of tansformation on the the DOM. Not pixels. You literally don't even know how CSS works. You also are clearly using a different mathematics to everyone else too. Go read the wiki page at least. And you still did not answer my question. If you can't put CSS in html2pdf, could you have a cellular automaton? – Cedric Mamo May 27 '19 at 04:49
  • @CedricMamo First of all I said "pixels" not pixels. Most thing that CSS affect is display/render things AKA "pixels" (e.g. result color of overleaping transparent DIVs with shadows). For your question "have a cellular automaton", you mean CSS as CA? In that case I can't prove or disprove that CSS is UTM. But my situation is different, I can wite html2pdf that will follow CSS specification (except for some animations but in our case its irrelevant) and in that case CSS is not enough to have make example that start this discussion work, this mean it working rely on things outside of CSS. – Yankes May 27 '19 at 18:21
  • 1
    and whether you put it in quotes or not, it's still wrong. CSS reads the DOM, and applies changes to the DOM. It is not responsible for rendering anything to the screen at all. That is not even CSS's job. – Cedric Mamo May 28 '19 at 03:39
  • @CedricMamo Last time I check CSS computed values are outside DOM (in sense html elements that CSS can read), you need use special function: `getComputedStyle` to get what finally style element have. And yes CSS do not need reader anything but it define what and how it will be rendered, is API for render, same as OpenGL, it too do not reader any thing but send commas to your Graphic Card. – Yankes May 28 '19 at 19:23
  • @CedricMamo I agree with you - I would say: `html+css is a semi-automatic programming language` (because it needs user to press tab+space) – Kamil Kiełczewski Oct 11 '22 at 19:41
5

Turing-completeness is not only about "defining functions" or "have ifs/loops/etc". For example, Haskell doesn't have "loop", lambda-calculus don't have "ifs", etc...

For example, this site: http://experthuman.com/programming-with-nothing. The author uses Ruby and create a "FizzBuzz" program with only closures (no strings, numbers, or anything like that)...

There are examples when people compute some arithmetical functions on Scala using only the type system

So, yes, in my opinion, CSS3+HTML is turing-complete (even if you can't exactly do any real computation with then without becoming crazy)

Maurício Szabo
  • 677
  • 1
  • 6
  • 13
  • 14
    Haskell and lambda-caclculus have recursion. Does CSS? You have to be crazy to do any real computation in Malbolge; in CSS, it doesn't matter how crazy you are: it won't work, CSS is not turing-complete, and that's not a matter of opinion. – JMCF125 Oct 14 '13 at 19:12
  • 1
    As I said in the comment above, CSS3 PLUS HTML is turing-complete, because it's able to compute Rule 110 (which is known to be turing-complete). Conway's Game of Life has no recursion, and it's turing-complete too. – Maurício Szabo Oct 15 '13 at 19:37
  • 12
    Sorry, I couldn't find any other comment of yours in this page. But as noted in the accepted answer it is Turing-complete " (...) so long as you consider (...) user interactions to be part of the “execution” of CSS". And I don't. – JMCF125 Oct 16 '13 at 10:38
  • 1
    @MaurícioSzabo: if the user manually advanced the state machine (kind of missing the "machine part here, but OK) AND the HTML document is infinite or dynamic and of unbounded size (but dynamic implies JS implies turing complete anyhow)... then sure, you can call CSS with a patient monkey and an infinite HTML document turing complete. But CSS by itself, or with a small, bounded number of user interactions, or with a static HTML document: not turing complete. – Eamon Nerbonne Feb 09 '14 at 14:21
  • 29
    Without intending to be offensive, turing completeness does not respond to anyone's opinion. – trisweb Sep 05 '14 at 14:08
  • 5
    @MaurícioSzabo No, CSS3 plus HTML plus *a human being continually stepping the simulation* is Turing complete. – Lambda Fairy Oct 19 '14 at 00:33
  • 7
    @LambdaFairy That's also true of every physical turing machine too. – Miles Rout Dec 08 '16 at 00:06
  • Cute. Defining lambda calculus in Perl. – Mike Rosoft Jun 05 '18 at 15:10
  • 1
    @LambdaFairy is C++ not Turing-complete because you need a CPU continually stepping the program? – OrangeDog Sep 03 '18 at 11:43
  • 1
    @OrangeDog the CPU is part of the computer. The user is not. – Lambda Fairy Sep 04 '18 at 06:15
  • 2
    @LambdaFairy neither are part of the language though – OrangeDog Sep 04 '18 at 07:19
  • 4
    @OrangeDog if you keep going with that argument, then MS Paint is Turing complete. Where do you draw the line? – Lambda Fairy Sep 04 '18 at 09:15
  • 3
    @LambdaFairy exactly where the definition tells you. Turing-completeness is a mathematical property of strictly-defined mathematical structures. Programming languages can be Turing-complete, no finite physical system (including a computer) can ever be. – OrangeDog Sep 04 '18 at 09:54
  • 1
    @OrangeDog CSS describes a mapping from the DOM to the computed style. The event loop that allows for simulating a Turing machine is in the scope of the overall HTML specification, not CSS itself. – Lambda Fairy Sep 04 '18 at 21:38
  • @LambdaFairy you could say the same thing for C++. The instructions that allows for executing a C++ program is in the scope of the compiler and CPU, not the C++ code itself. But Turing completeness isn't about how it's executed. It's about how powerful a language is at defining patterns and relationships. The patterns and relationships defined by CSS "mappings" is as powerful as the patterns described by a Rule 110 automata, so that's what makes it turing complete – woojoo666 Mar 25 '19 at 10:46
  • 2
    Well isn't the user repeatedly pressing a button just the same thing as what the system clock does to the CPU? Just as long as the user doesn't have to make any decisions about what to press, it's equivalent. You encode your problem, any computable problem, and then whatever that problem is you just do the same thing: drive the "system clock". Suppose you wrote a short Javascript function to just look and keep pressing the same button programmatically. The JS function definitely wouldn't be Turing complete. The computation would be done by CSS. What or who drives the clock is irrelevant. – Cedric Mamo May 10 '19 at 13:28
-37

CSS is not a programming language, so the question of turing-completeness is a meaningless one. If programming extensions are added to CSS such as was the case in IE6 then that new synthesis is a whole different thing.

CSS is merely a description of styles; it does not have any logic, and its structure is flat.

Ryan Prior
  • 1,499
  • 11
  • 22
  • 1
    Also (IIRC), there is some ambiguity about which styles take precedence when multiple conflicting (duplicate) styles are used. And then there is the slightly different ways that different browsers implement/interpret markup styles to deal with. – David R Tribble Mar 23 '10 at 02:40
  • 82
    *"CSS is not a programming language, so the question of turing-completeness is a meaningless one."* Tautological sentences are tautological. – Adam Davis Mar 23 '10 at 13:10
  • 8
    Take a look at the programming language Prolog if you wonder why your answer is downvoted so much. – edwin Jan 15 '19 at 22:31