@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)
– kibibuMar 23 '10 at 3:20

7 Answers
7

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:

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.
– JohnJun 11 '18 at 21:32

2

This snippet doesn't appear to work (Firefox 61). I see a grid of empty checkboxes - nothing happens if you check them.
– OrangeDogSep 3 '18 at 11:38

@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
– woojoo666Mar 5 at 2:21

That's it. Since we just showed that the halting problem is decidable 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.

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 😉

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.
– philixAug 13 '15 at 12:41

30

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 WagnerOct 6 '15 at 3:23

@asmeurer The answer uses modus tollens, which is a valid form of argument. Turing complete implies undecidable, ergo, decidable implies not Turing complete. There may be issues with the specification of the problem (as Daniel noted) but the logic itself is sound.
– Lambda FairyJan 13 '17 at 22:17

3

@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 ShiJan 21 '17 at 21:33

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.

CSS isn't executable in any way. The person who wrote the quoted comment doesn't seem to understand that. :-\
– Ryan PriorMar 23 '10 at 3:01

31

CSS is a set of instructions to a processor (layout engine). What's so not "executable" about it?
– DVKMar 23 '10 at 3:26

42

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 MayerJun 14 '13 at 9:30

12

@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
– DVKMay 2 '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 :).
– mınxomaτAug 9 '16 at 7:55

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.
– JMCF125Oct 14 '13 at 19:12

11

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.
– JMCF125Oct 16 '13 at 10:38

15

Without intending to be offensive, turing completeness does not respond to anyone's opinion.
– triswebSep 5 '14 at 14:08

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.

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 DavisJun 14 '16 at 17:26

1

@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.
– 00daniOct 7 '16 at 10:22

@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 FairyJan 14 '17 at 1: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 DavisJan 14 '17 at 3:21

3

It's not if B then A! It's if not B then not A! The former is affirming the consequent, which you correctly point out is wrong. The latter, argument 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 FairyJan 14 '17 at 7:04

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.

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.
– OrangeDogSep 19 '18 at 9: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 MamoMay 10 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 MamoMay 10 at 13:50

@CedricMamo But your clicks change state, and you need click only correct places other wise it would not work. Look exactly on 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.
– YankesMay 11 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 MamoMay 11 at 18:31

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.

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 TribbleMar 23 '10 at 2:40

69

"CSS is not a programming language, so the question of turing-completeness is a meaningless one." Tautological sentences are tautological.
– Adam DavisMar 23 '10 at 13:10

1

Take a look at the programming language Prolog if you wonder why your answer is downvoted so much.
– edwinJan 15 at 22:31