You are currently viewing Currency Formatter With HTML, CSS, & JavaScript

Currency Formatter With HTML, CSS, & JavaScript

Currency Formatter With HTML, CSS, & JavaScript

Hello everyone. Welcome to today’s tutorial on Codewithrandom. We’ll learn how to make a Currency Formatter in which the currency value is shown as per the country rupee such as $USD & INR . In Today’s session, We will use HTML, CSS, and JavaScript to complete this Currency Formatter Project.

Project Description

Step 1

The HTML (Hypertext Markup Language) will help us to create the structure for the list with some necessary attributes and elements to make the Currency Formatter Project.

Step 2

Then we will use CSS (Cascading Stylesheet) which will help us to style or design the project with suitable padding and alignment in the Currency Formatter Project.

Step 3

At last we will use JS (JavaScript) which will add a logic to make the Currency Formatter Project responsive from the user end.

I hope you have got an idea about the project.

HTML Code for Currency Formatter

<html lang="en">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Currency Formatter</title>
    <!--Google Font-->
    <link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;500&display=swap" rel="stylesheet">
    <!--Stylesheet-->
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="wrapper">
        <div class="container">
            <input type="text" id="amount" placeholder="Enter the amount here">
            <button id="btn">Format</button>
        </div>
        <p id="output1">
            <span>Indian Rupees:</span>
        </p>
        <p id="output2">
            <span>US Dollars:</span>
        </p>
        <p id="output3">
            <span>Japanese Yen:</span>
        </p>
    </div>
    <!--Script-->
    <script src="script.js"></script>
</body>
</html>

First we’ll start with creating the structure of the Currency Formatter project for that as you can see the above code we have used all the necessary elements & attributes to setup the structure. Let us know code the CSS part to add styling and aligned the tags.

Aspect Ratio Calculator using HTML, CSS &JavaScript

CSS Code for Currency Formatter

*{
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    font-family: "Roboto Mono",monospace;
}
body{
    height: 100vh;
    background: linear-gradient(
        135deg,
        #a283fc,
        #6637ed
    ), #fafcfe;
    background-size: 100% 32%;
    background-repeat: no-repeat;
}
.wrapper{
    width: 80vmin;
    position: absolute;
    transform: translate(-50%,-50%);
    top: 50%;
    left: 50%;
}
.container{
    width: 100%;
    background-color: #ffffff;
    box-shadow: 15px 15px 40px rgba(1,9,31,0.05);
    padding: 40px 30px;
    border-radius: 5px;
    display: grid;
    grid-template-columns: 3fr 1fr;
    grid-gap: 20px;
}
input{
    height: 40px;
    outline: none;
    border: none;
    color: #37373a;
    font-size: 16px;
    border-bottom: 1px solid #37373a;
}
button{
    background-color: #6637ed;
    border: none;
    color: #ffffff;
    outline: none;
    height: 40px;
    padding: 0 20px;
    cursor: pointer;
    border-radius: 3px;
}
p{
    background-color: #ffffff;
    box-shadow: 12px 12px 30px rgba(1,9,31,0.05);
    padding: 20px 10px;
    text-align: center;
    margin-top: 30px;
    color: #37373a;
    border-radius: 5px;
}
p span{
    font-weight: bold;
}

Second, comes the CSS code which we have styled for the structure we have padded as well as aligned the Currency Formatter project so that it is properly situated and doesn’t get messy with suitable CSS elements. Now lets code the JavaScript part to make responsive.

Random Hex Code Generator Using HTML, CSS, and JavaScript

JavaScript Code for Currency Formatter

let btn = document.getElementById("btn");

let rupees = document.getElementById("output1");
let dollars = document.getElementById("output2");
let yen = document.getElementById("output3");

let formatter1 = new Intl.NumberFormat(
    "en-IN",
    {style: "currency", currency: "INR"}
);
let formatter2 = new Intl.NumberFormat(
    "en-US",
    {style: "currency", currency: "USD"}
)
let formatter3 = new Intl.NumberFormat(
    "ja-JP",
    {style: "currency", currency: "JPY"}
)

btn.addEventListener("click", ()=>{
    let amount = document.getElementById("amount").value;

    rupees.innerHTML = `<span>Indian Rupees:</span>${formatter1.format(amount)}`;
    dollars.innerHTML = `<span>US Dollars:</span>${formatter2.format(amount)}`;
    yen.innerHTML = `<span>Japanese Yen:</span>${formatter3.format(amount)}`;
});

Last stage of the project the JavaScript in which we have added the logical and coded as per the requirement with some conditions and we have also set how the different currency output should be displayed. Let us see the Final Output of the project Currency Formatter With HTML, CSS & JavaScript.

Final Output


We have successfully created our Currency Formatter With HTML, CSS & JavaScript. You can use this project for your personal needs and the respective lines of code are given with the code pen link mentioned above.

If you find out this Blog helpful, then make sure to search code with random on google for Front End Projects with Source codes and make sure to Follow the Code with Random Instagram page.

Thank You And Keep Learning!!!

Code Idea – codingartist

Written By – Harsh Sawant

Code By – @harshh9

Leave a Reply