Tip Calculator using HTML, CSS & JavaScript
Tags: webdev, javascript, beginners, programming
Published: 2022-11-21 11:00:00

Hello Guys! Welcome to [Coding Torque](https://codingtorque.com). In this blog, I'm going to explain to you how to make a tip calculator using HTML, CSS, and JavaScript. This will be a step-by-step guide including HTML and CSS. Let's get started 🚀.

## **Let's cover HTML Part**
We use HTML to make the skeleton of a website. HTML is a markup language.

Now let's import the font awesome CDN in our HTML `<head>` tag. fontawesome is a library that is used for icons in a website.

```html
<!-- Font Awesome Icons  -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css"
integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA==" crossorigin="anonymous" />
```


Now let's import the fonts using Google Fonts API. Below is the code for `Poppins` Font. Paste the below code in `<head>` tag.

```html
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
```

## **Here is the final HTML code**

```html
<!DOCTYPE html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Font Awesome Icons  -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css"
        integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA=="
        crossorigin="anonymous" />

    <!-- Google Fonts  -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">

    <title>Tip Calculator using JavaScript - @code.scientist x @codingtorque</title>
</head>

<body>
    <div class="calculator">
        <label for="totalBill">Bill</label>
        <input type="number" oninput="calculateTip()" onchange="calculateTip()" id="totalBill"
            placeholder="Enter Your Bill">
        <label for="tipPercentage" style="display: flex; justify-content:space-between;">
            <span>Tip %</span>
            <span id="tipPercentageText">15%</span>
        </label>
        <input type="range" oninput="calculateTip()" onchange="calculateTip()" id="tipPercentage">
        <label for="numOfPerson" style="display: flex; justify-content:space-between;">
            <span>
                No. of people
            </span>
            <span id="numOfPersonText">15</span>
        </label>
        <input type="range" oninput="calculateTip()" onchange="calculateTip()" id="numOfPerson">
        <div class="result" id="result">
            <h5 style="margin: 8px 0;display: flex; justify-content:space-between;">
                <span>Tip</span>
                <span style="font-size:1.2rem;">__.__</spam>
            </h5>
            <h5 style="margin: 8px 0;display: flex; justify-content:space-between;">
                <span>Total</span>
                <span style="font-size:1.2rem;">__.__</spam>
            </h5>
            <h5 style="margin: 8px 0;display: flex; justify-content:space-between;">
                <span>Each Person Pay</span>
                <span style="font-size:1.2rem;">__.__</spam>
            </h5>
        </div>
    </div>

</body>

</html>
```

[continue reading](https://www.codingtorque.com/2022/09/tip-calculator-using-html-css-and.html)