Lesson learned through the responses I got for my OOP article: The internet will come after you for being even slightly inaccurate. With that in mind, I decided to write an article just to troll language purists and gatekeepers. π
Just as a heads-up: Most of this article is basically a meme. If you completely agree with everything here, you probably didn’t pay attention.
Why HTML Should Be Considered A Programming Language
First things first: We need to define what exactly a programming language is, before figuring out if (and why) we can call HTML a programming language.
Instead of data transformations or other abstract stuff, let’s go with a simple definition:
A programming language is a formal computer language with defined syntax and semantics, that is used to tell a computer what to do.
It doesn’t matter, whether the language specifies what the end result should be (= “declarative”), or how to do it (= “imperative”), whether another program is used to run it (= “interpreted”), or whether it’s translated to another language or machine instructions (= “compiled”). As long as it instructs the computer to do stuff, it’s a programming language.
Does HTML have a formal definition?
The first line of every HTML file contains the document type declaration that specifies which language definition to use. Old-school HTML doctypes even contain a link to the relevant document type definition (DTD).
HTML 5 doesn’t have a DTD. However, there is still a (somewhat) formal definition on the website of the Web Hypertext Application Technology Working Group (or WHATWG for short – what a mouthful; Sounds like an American exchange student in Germany asking their classmates where they live… No? Too niche? Okay. π )
Random fun fact: HTML doctypes actually allow Spongebob-case:
<!DoCtYPe html>
Code language: HTTP (http)
Does HTML tell the computer, what to do?
HTML specifies where to put tables, images, headings, texts, etc. and how to format them. It’s not just a pure data language like XML, JSON, YAML or TOML. There is semantics attached to it. And the web browser essentially interprets the HTML program.
Argument by Authority
Surely, no expert would ever consider HTML a programming language, right?
Let me direct you to the video “HTML IS a Programming Language (Imperative vs Declarative)” by Computerphile on Youtube. The guy in the video is David Brailsford, a professor for Computer Science and Information Technology at the University of Nottingham.
But it’s not just old professors that think HTML is a programming language. The VS Code documentation also talks about “HTML programming”. As does computerscience.org.
Why HTML Shouldn’t Be Considered A Programming Language
Okay, so now that I’ve explained why HTML is a programming language, let’s address some common arguments why it’s not. My main counterargument will be, that narrowing the definition to exclude HTML will very likely also exclude other languages that are generally considered programming languages. I’m not saying these arguments are wrong, I’m just following the reasoning to its logical conclusion.
HTML only describes how the page should look like. That’s not programming.
You think so? Okay, what about PostScript then?
PostScript is a Turing-complete page-description language used for printing. It has loops, conditions, the whole shebang. PostScript can even – in contrast to something like PDF, ZPL or DVI – be used for general-purpose programming. So, if HTML is not a programming language because it describes how something should look like, PostScript wouldn’t be a programming language either, no?
HTML is not general-purpose.
HTML is a so-called domain specific language (DSL). It is designed specifically for displaying and formatting content in a web browser. The thing is, though: There are a lot of domain specific languages out there, that can be considered programming languages.
SQL with recursive CTEs is actually Turing-complete, you can use it to compute anything. So is the macro language in TeX (since version 82).
MATLAB, Maxima and the like are also Turing-complete, and can even have a graphical output. A friend of mine once implemented a drunkard’s walk simulation in Maxima. And for a course at uni, we had to implement a 3D rendering engine in MATLAB.
Another example: I once built a convertor for Roman numerals purely in YACC, a language specifically designed to build compilers. Instead of constructing an AST, the rule actions just calculate the current value. Of course, printing the result and adding the node values is actually C code, but all the logic is generated by YACC.
What about CNC programming (G-code)? Or PLCs (FBD, LD, IL, …)? Or FPGAs (VHDL)? Still considered programming, even though these languages are not general-purpose.
So, just because a language is meant for a specific application doesn’t mean it can’t be used more generally as well. It also doesn’t mean it’s not a programming language.
HTML doesn’t have any loops or conditional statements.
Most programming languages have keywords for loops and conditions. HTML, by contrast, does not. Similar to languages like Haskell… kinda.
Functional languages usually don’t have loops in the traditional sense, as they require side effects to work. Instead, Haskell has things like the forever
and iterate
functions, list comprehensions and, of course, list functions like map
, fold
, and so on. Everything else is done using recursion.
Haskell also doesn’t have conditional statements. The way to deal with conditional control flow is to use if
expressions (or pattern matching) in combination with lazy-evaluation.
HTML is not Turing-complete.
Since HTML does not support recursion, or loops with mutable state, it is not able to model a Turing machine. However, there are other programming languages that are also not Turing-complete.
SQL without CTEs is not Turing-complete either, but is still a very commonly used programming language. (Yes, it is. I know it’s bad taste to quote Wikipedia, but: “SQL is a set-based, declarative programming language […]”)
Another example is Datalog, a logic programming language that – unlike Prolog – is not Turing-complete. In fact, the whole field of Answer Set Programming (ASP) is not Turing-complete. And it even has “programming” in the name. So, I think we can agree, that Turing-completeness is not necessary for a programming language.
Also, fun fact: HTML + CSS is (in a sense) Turing-complete. You can build a Rule 110 automaton with it.
HTML is not compiled.
I wasn’t sure whether to include this point, as it sounds ridiculous to me. But since I’ve heard it at least once, I decided to add it anyway.
The argument was: Interpreted languages are not programming languages as the computer is not executing the programs directly.
However, I donβt think many people share this view. Let’s be real: Almost everybody agrees that languages like Python or JavaScript are, in fact, programming languages.
(Actually, this might be a fun project: Building an HTML compiler. It takes the HTML file, and generates an executable that displays its contents in a window.)
If HTML is a programming language, so is XML.
XML is actually very different from HTML. XML is a way of structuring information. It doesn’t have any defined semantics. HTML just happens to use an XML-style structure.
We could just as well construct a “proper” programming language that uses XML. In fact, I did a few years ago to prove a point. Took me like an afternoon or so. I used Go’s built-in XML unmarshaller, and thus completely skipped the parsing step. The interpreter then just walks the AST directly. It’s not fast by any means, but it works.
Another example of a programming language using XML for its structure is XSLT: A declarative, Turing-complete language designed for transforming XML files.
Not related to XML, but there is also YAMLScript, a functional programming language that uses YAML as its syntax.
(Video recommendation: “HTML: Poison or Panacea?”, also by Computerphile. The topic is how HTML got its DTD to become SGML-compliant, and how XML happened as a side effect.)
If HTML is a programming language, so is Markdown.
Sure, why not. It, too, is a specification of how the computer should display the content.
Another fun fact: Markdown was originally compiled into HTML. In a sense, it is to HTML, what TypeScript is to JavaScript.
Is this really important?
You might be thinking: “Why are we arguing about this? Does it really matter, whether HTML is a programming language?”
The answer is: No, it does not matter. It’s completely irrelevant. That’s exactly the point.
For some reason, people are obsessed with categories, and get mad when something doesn’t fit their world view.
Sometimes I feel like the only reason why some people insist that HTML is not a programming language, is to not let newcomers that are just starting out with HTML, call themselves “programers”.
It’s gatekeeping at its best. “You are not a real programer unless you can write a POSIX-compliant operating system… purely in x64 assembly… blindfolded.”
Here are my two cents: The word “programer” is completely useless without a qualifier anyway. Programming disciplines are so incredibly diverse. Two programmers in different areas might not even be able to understand each other properly.
Blocks and cycles in PLC programming, templates and concepts in C++, functors and monads in Haskell, facts and rules in Prolog, borrows in Rust, struct tags in Go, bidirectional isolation in HTML, … Each area has its own concepts and language.
“I’m a programer” is about as interesting as saying “I work with computers”. So why insist on the distinction? Especially since we can’t even settle on a coherent definition anyway.
Conclusion
The point of this article is to demonstrate that it’s hard to find good definitions, and sometimes there is simply no point in finding one.
The takeaway should be: HTML is a programming language. It doesn’t matter.
Okay, somehow I managed to write an article about HTML, without even touching on XHTML and JSX (btw: JSX markup is not a programming language – no defined semantics). I’m almost proud of myself. Maybe I’m getting better at concise writing after all. π
In any case: I hope you found this article interesting, or at least somewhat entertaining.
Have a wonderful day,
Sigma
One response to “HTML Is A Programming Language”
I just wanted to give feedback and say: I love your article. I actually think programming goes much further than decorative scripting languages at the simple end. Somehow we’re always talking about programming when a human is telling a machine – be it the alarm clock, the clock on the oven or setting preferences in an app via a graphical interface. We are all programmers and should then say what interface and/or language we are using – instead of categorizing based on a language. You’re a real programmer because you need a compiler – bullshit. Real programmers push the bytes directly into the register ^^ It’s like when my mom calls about a problem with the Wi-Fi. I can only say: Yes, I can talk to computers in many languages, but I have no idea about router configuration or network settings on Windows. But it usually helps to unplug the phone after a few minutes anyway π