As far as my understanding goes, CSS is not considered Turing complete. However, I admit that my knowledge of CSS is quite limited.
Can CSS be classified as Turing complete?
As far as my understanding goes, CSS is not considered Turing complete. However, I admit that my knowledge of CSS is quite limited.
Can CSS be classified as Turing complete?
One interesting way to demonstrate the Turing-completeness of CSS3 is by encoding Rule 110 using it. This involves creating an HTML file with appropriate user interactions to simulate the execution of CSS. You can find a well-implemented version here, and below is another implementation:
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;
}
... (CSS code continues)
<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 -->
... (HTML code continues)
One concept related to Turing completeness involves the famous halting problem.
This implies that if CSS were to be considered Turing complete, there would not exist a universal method for determining whether a CSS program will terminate its execution or continue indefinitely.
However, we can actually devise such a method specifically for CSS! Here's how:
If the stylesheet does not include any animations, then it will eventually stop running.
If animations are present, then:
If any animation-iteration-count
is set to infinite
, and the corresponding selector is matched in the HTML, then it will keep looping endlessly without halting.
Otherwise, it will eventually halt.
In conclusion, as we have successfully addressed the halting problem within the context of CSS, it logically follows that CSS is not Turing complete.
(It has been pointed out by Daniel Wagner that considerations besides animations, like selector matching or layout, could potentially contribute to achieving Turing completeness. Nonetheless, formal arguments supporting this remain challenging, but I will attempt to explain why such an occurrence is improbable.)
Firstly: Languages that are Turing complete have mechanisms for recursively feeding data back into themselves. However, the structure of CSS itself inhibits this feedback loop:
@media
queries only assess properties of the browser environment, such as viewport dimensions or screen resolution. While these properties may vary due to user actions or JavaScript manipulation (e.g., resizing the window), they cannot be altered solely through CSS directives.
The pseudo-elements ::before
and ::after
are considered separate from the DOM structure and thus pose limitations on possible interactions.
Selector combinators facilitate inspections of elements above or preceding the current element, hence preventing cyclic dependencies.
Although it is feasible to hover over an element and trigger behaviors like moving it, the computed changes occur only with ongoing mouse movement.
This rationale should convince you that solely relying on selector matching is insufficient to achieve Turing completeness. What about layout functionalities?
The intricate nature of modern CSS layouts involving techniques like Flexbox and Grid adds complexity to the scenario. Even supposing infinite loops could somehow be triggered through layout operations, capitalizing on this for practical computations would prove arduous. This difficulty arises from CSS selectors addressing only internal structural aspects of the DOM rather than real-time screen arrangement. Thus, any argument asserting Turing completeness via layout functions must rely exclusively on layout components.
Lastly – and critically important – browser developers intentionally maintain CSS as non-Turing complete. By imposing constraints on the language, developers foster opportunities for efficient optimizations that enhance web performance universally. Moreover, Google allocates significant resources, like an entire server farm, towards identifying bugs in Chrome. If a loophole existed allowing for indefinite loops using CSS, it would likely have been detected already 😉
According to the source I found, it's clear that CSS is not Turing complete. The article makes a strong case against trying to make it one.
In one insightful comment from the article:
Indeed, I don't believe that CSS has the characteristics of being Turing complete. The absence of functions in CSS prevents the possibility of writing an interpreter, an essential component for a system to be considered Turing-complete. With no direct access to variables or the ability to represent program structures in CSS, achieving Turing completeness seems unattainable.
This response is incorrect as it blends descriptions of UTM with the Universal Turing Machine itself.
While we do have a solid response from a different angle, it does not directly highlight the flaws in the current top answer.
Let's start by acknowledging that humans can function as a UTM. This implies that if we were to do:
CSS + Human == UTM
The CSS
component becomes redundant since all tasks can be carried out by the Human
who will perform the UTM task. The act of clicking could serve as a UTM because clicks are targeted rather than random.
Instead of CSS, I might utilize this text (Rule 110):
000 -> 0
001 -> 1
010 -> 1
011 -> 1
100 -> 0
101 -> 1
110 -> 1
111 -> 0
To direct my actions with the same outcome. Consequently, is this text a UTM? No, it merely serves as input (description) for other UTMs (be it human or computer) to decipher and execute. Clicking alone is sufficient to operate any UTM.
The key deficiency in CSS is its inability to autonomously modify its state arbitrarily. If CSS had the capability to trigger clicks, then it would qualify as a UTM. The argument that your clicks act as a "crank" for CSS is inaccurate since the real "crank" for CSS is the Layout Engine that powers it, serving as ample evidence that CSS is indeed a UTM.
One of the key challenges presented here is that a machine coded in HTML+CSS lacks the ability to process an infinite number of steps (meaning true recursion is not possible) unless the code itself is of infinite length. The inquiry of whether this machine will achieve configuration H
within n
steps or fewer can always be definitively answered as long as n
is a finite value.
Turing completeness goes beyond just "defining functions" or "having ifs/loops/etc". For instance, Haskell lacks "loop", lambda-calculus lacks "ifs", and so on...
One interesting example is showcased on this website: . The author demonstrates creating a "FizzBuzz" program in Ruby using only closures (without utilizing strings, numbers, or any other data types)...
There are instances where individuals have managed to perform arithmetical computations in Scala solely through the type system
Therefore, I believe that CSS3+HTML can be considered turing-complete (even though practical computation may not be feasible without driving oneself insane)
Did you know that CSS is considered Turing-complete? And the most interesting part is, it doesn't need any user interaction to execute programs.
Believe it or not, in CSS you can actually run finite Boolean circuits and even Turing machines, as long as there is a stationary mouse cursor available to activate the :hover
rules. It's quite fascinating how CSS can handle such complex operations!
Check out this link for more information on CSS being Turing-complete.
Just so you know, these samples were personally developed by me. To my knowledge, this is one of the first fully functional Turing machines created using pure CSS.
Unlike programming languages, CSS is focused on styling elements and is not considered a true programming language. The concept of turing-completeness does not apply to CSS since it lacks the necessary logic for computation. When additional programming features are introduced to CSS, such as in the case of IE6, it transforms into something entirely different.
CSS remains a tool for visual design, offering a straightforward and linear approach to defining styles for web elements.
Struggling to implement Ng-bootstrap's 'ngbPopover' functionality, I encountered a frustrating issue where the popover would not display after clicking the button. After numerous hours of troubleshooting, I was relieved to discover the root ...
* { box-sizing: border-box; padding: 0; margin: 0; } ul { list-style-type: none; } .nav-links, .logo { text-decoration: none; color: #000; } .logo { max-width: 80%; width: 20%; height: 20%; } .navbar { padding: 20px; height: 50vh; ...
Displayed above are 4 different divs: red, green, and blue. I am seeking to have the blue div positioned directly below the green div, which contains the text "JACKSON". Additionally, I do not want the green div to expand beyond its content, nor do I want ...
As a newcomer to development, I am currently experimenting and creating a sample dashboard. However, I am facing an issue where the sidebar value does not display upon loading the page. I have to manually click on a list in my sidebar for it to appear. Th ...
I am currently working on the menu structure for my website <div class="header"> <ul> <li id="menu__lnk_one"><a href="#">Home</a></li> <li><a href="#">Our Story</a></ ...
Struggling to implement a navigation menu within a self-scrolling div using html/css/jquery. Looking for the menu items to toggle the active class when in view or at the top of the scrolling div. I'm essentially trying to achieve something like this ...
I am looking to update the URL that Bootstrap uses to access fonts, as I want to host them on my server instead of relying on users to fetch them from Google with each page load. However, despite my efforts, I cannot locate the specific URLs mentioned when ...
Currently in the development phase of my epubReader app. Utilizing CSS to customize the font style within UIWebView, however encountering a challenge with the fixed font size causing fluctuations in the number of pages when changing the font style. Seeki ...
I'm struggling with creating Navbars in Grid Layout. https://codepen.io/Aeshtray/pen/BdqeZL For mobile view, I want the Navbar to be fixed horizontally (as currently coded), but once reaching a width of 500px, I need it to become vertically fixed on ...
Is there a way to select only one checkbox out of two? I know it can be done easily using Jquery, but is there a default option in HTML for this as well? I have exactly 2 checkboxes. Thank you. code: <input type="checkbox" value="1" name="foo" /> ...
I need help figuring out how to create a variable in my script that is defined by the width attribute of a CSS class. The snippet I have currently doesn't seem to work as expected. var dist = $('.nav').css(width()); The goal of my script i ...
Please take a look at the code snippet below. $(document).ready(function(){ $(".like-btn").hover(function() { var rowid = $(this).attr("data-rowid"); $(".reaction-box[data-rowid='" + rowid + "']").fadeIn(100, function() { $(".reaction ...
I'm in need of assistance. When viewing my website in mobile mode, the collapse hamburger menu is hiding too far to the right. This issue is making the site look unresponsive, and I've been unable to find a solution. It seems like the problem sta ...
Is there a way to toggle a div's visibility between collapsed and expanded, transitioning smoothly from right to left? I've noticed that most examples I come across demonstrate the transition from left to right. ...
I am currently working with Longtail's JW Player and facing some difficulties with a basic function. Since I am not familiar with the programming language terminologies, I will describe the issue step by step: There is a JavaScript code that displays ...
I am currently working on a movie listing website where all the movies are displayed in sequence based on their #TITLE#. The webpage is generated automatically by the software using a template file. Here is the section of code in the template file that sho ...
In the scenario of a single-page website with various sections (divs) and a header containing links to different anchors on the page, there is a desire to have an indicator highlight which anchor the user is currently viewing. An example of this can be s ...
DisplayBooks.vue consists of a single page responsible for showcasing books fetched from a backend API. Each card on the UI features two buttons - ADD TO BAG and ADDED TO BAG. When a user clicks on the ADD TO BAG button of a specific card, it should toggle ...
Alright, let's get to it - I've got a couple of SVGs here. The first one is a blue circle and the second one is a map of the United States. (Both of these were created in Illustrator) Here's what I want to do: I want the map to serve as a ...
I've set up 2 dropdown menus, but I'm having trouble adjusting their size. I need them to fill the screen width. Here's my code: <select id="repeatSelect" ng-model="selectedArea"> <option ng-repeat="(key,prop) in result" value=" ...