Back to Blog List

No, HTML IS a Programming Language

Published | 4 min read

Three years ago when I got into Web Development, I was strictly told I have to be careful with anyone fooling me into thinking that HTML is a programming language. Instead, I should be clever and if someone asks me about HTML, I should answer confidently, nope, it’s a Markup Language. Sure enough, I was satisfied with that conclusion back then.

Time has passed and one day I found myself asking: wait, but what is a Markup Language? After not a lot of search I found that a markup language is a text-encoding system which specifies the structure and formatting of a document and potentially the relationships among its parts.

Well that was a mouthful but then I asked myself: a system which specifies the structure and formatting, yes but to whom? To the computer! But isn’t the act of telling a computer something is programming? It basically is. To program is to ask the computer to do something.

Honestly, this idea was mind blowing to me! So I started ruminating over it for quite sometime and I’ll try to reflect my thoughts about it here.

First an intuitive objection to this would be that we don’t write programs with it, we just decide the formatting of the document, as we don’t write code, we write tags! And the answer is that what do these tags actually do? They tell (program) the browser - the computer - to do certain logic that results in this behavior / format we intend.

Here’s an example: Look at this code:

<p>Hello, world!</p>

In this example we write a p tag to format the text in a specifc way. Now, how about this?

const displayResult = p("Hello, world!")
render(displayResult)

Notice any difference? For me they’re the same! Both function p and render are blackboxes for us. It’s basically the same with the first the example, think of the <p> tag as a blackbox, a function, that takes a text as an argument and results in the text being fomratted in a specific way. The thing is, in this case, we don’t think of the underlying logic, how the browser does this behavior, we only care about the result. The underlying logic (code) is a blackbox for us.

A classic concept that would be very helpful for us here is the difference between Declarative and Imperative programming.

Imperative Programming is telling the computer how to do something, a step by step, controlling the flow, the state, the exact operations, etc.. An example of that would be something like this:

const button = document.createElement('button') //Step A: Create the element `button`
button.innerText = 'Click me' // Step B: Set its inner text to this
button.addEventListener('click', () => { // Step C: Attach the event `click` and when click do something
  console.log('Clicked')
})
document.body.appendChild(button) //Step D: Append the button the the DOM body

Declarative Programming is describing what you want from the computer, NOT how to do it, the system figure out the steps, most of the times it was written ahead for us and abstracted as a black box to consume. Tthe same example above would look something like this, if it was declarative:

<button @click="handleClick">
  Click me
</button>

Both are ways of writing code and doing programming, they’re just different. Each has its own pros and cons. A general purpose programming language (like most “real” programming languages, e.g. C, Javascript, Python, etc…) usually can contain both programming paradigms, and deciding which way and which context to use which is the user’s choice.

But now someone would say: “But HTML is not a general purpose programming language, you cannot wiite imperative code in it”, and the answer for this is that Yes, it’s true that HTML is NOT a general purpose programming language, though it still A Programming Language…And a Markup language! It’s basically both, depending on how you want to see it!

Anyhow, I want to keep this article simple for now, I’m not willing to throw many ideas like Turing-Completeness, Execution Engine, Historical Context and further arguments and counter arguments. I prefer this to be just a thought-provocotive article that open for discussion and counter arguments.

Finally, before I write this earticle, I went to search about similar content with the same idea and I came across this video: Is HTML A Programming Language?, it discuss further counter-argumenrts and the answer for each one, it’s very interestig and digs a little bit deeper. I’ll leave you with it. And if you have further thoughts or counter-argument about this, feel free to reach me out!