Is HTML a Programming Language?

When we talk about a programming language, we can say them as a medium to communicate with the computer. To express ourselves, we as humans talk with each other using any of our native languages but we cannot simply communicate with the computer the same way.

It simply can’t understand our native language. Instead, we need a translator who can translate our language into a computer’s language.

Now, before talking about the translator, I want to talk about the topic of today’s post, i.e. is HTML a programming language?

HTML is a declarative programming language. What does that mean? Well, a declarative programming language is a paradigm that only states what the result should look like and not hot to achieve it. We use basic statements for achieving something we want. Here we use constraints to describe a user interface.

User Interface

This is how we use constraints for creating a UI using HTML.

<!DOCTYPE html>
<html>
  <head>
    <title>Page Title</title>
  </head>
  <body>
    <h1>This is a Heading</h1>
    <p>This is a paragraph.</p>
  </body>
</html>

These constraints are going to describe the structure of our UI. Here the h1 is going to be a heading of our UI and the p is going to be the paragraph of our UI. The HTML parser or the HTML engine of the browser is going to render the UI from the above constraints. Here, we haven’t described how to achieve our desired UI.

Whereas in other programming languages, we have to teach a computer how to achieve a particular result. For example, if we want to make a simple calculator, we need to show the computer how to do that.

a = int(input('Enter number'))
b = int(input('Enter number'))

c = a + b

print ('Sum of a and b is: {0}'.format(c))

All these programming logic can’t be implemented using HTML and can only be achieved when we use Javascript, a type of programming language for the web.

So, how to implement the same logic using HTML and JS? Let’s see.

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>Add two numbers</title>
    </head>
    <body>
        <input type="number" name="first_num" id="x" placeholder="Enter first number"/>
        <br />
        <input type="number" name="second_num" id="y" placeholder="Enter second number"/>
        <br />
        <button id="go">Calculate</button>
        
        <div id="result"></div>
        
        <script>
            "use strict";
            function add() {
                var x = Number(document.getElementById('x').value);
                var y = Number(document.getElementById('y').value);
            
                document.getElementById('result').innerHTML = x+y;
                return false;
            }
            
            document.getElementById('go').addEventListener('click', add);
        </script>
    </body>
</html>

This states that we can’t implement programming logic in HTML but we can achieve that using Javascript.

Now, I hope you get what I’m trying to say for HTML.

Well, this was all about today’s topic and points related to it. If you stuck into any kind of confusion, don’t forget to google it and try to solve it on your own. This will teach you how to learn on your own as someone might have faced a similar problem earlier.

Still, if you still don’t find any solution for your problem, you can ask your doubt in the comment’s section below and we’ll get back to you🤓. Till then enjoy your code. See you in my next post. Bye✌️!

Leave a Comment

Your email address will not be published. Required fields are marked *