Create a Height Converter Using HTML, CSS, & JavaScript

Height Converter Using HTML & JavaScript (Source Code)

Height Converter Using HTML, CSS, and JavaScript

Hello Coder, Welcome To the Codewithrandom Blog. Today We are going to Create A Height Converter Using Html, Css, And JavaScript. In this Height Converter, you enter Feet and Inches and It Converts into Centimeter.

Create a Height Converter HTML CSS JavaScript Code
Create a Height Converter HTML CSS JavaScript Code

 

It is a beginner project in which we will clear all the concepts of forms for taking input from the user and then use the javascript concepts to convert the height accordingly so convert them from feet into the center.

50+ HTML, CSS and JavaScript Projects With Source Code

Inputs here consist of two. You can enter the first one in feet and the second one in millimeters. All of the computations can be seen on a display that is also included. To create this height converter, I used HTML, CSS, and JavaScript. CSS’s fundamentals were created by HTML, and JavaScript implemented them.

Live Preview Of Height Converter:-


I Hope You Enjoy Our Blog So Let’s Start With A Basic Html Structure For The Height Converter.

Restaurant Website Using HTML and CSS

Html Code For Height Converter:-

<!DOCTYPE html>
<html>
<head>
<title>Height Converter</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="container">
<h1>Height Converter</h1>
Feet
<input type="text" id="feet" /> <br />
Inches
<input type="text" id="inches" /> <br />
<input type="submit" id="submit" value="Convert to cm" /> <br /><br />
<div id="result"></div>
</div>
<script src="app.js"></script>
</body>
</html>

We need to add a few connections to our stylesheet before building the framework for our height calculator. We will add the link for the stylesheet using the external CSS file. Since we also made the file for the javascript, we also need to add the link for it inside the body tag.

<link rel="stylesheet" href="style.css">
<script src="script.js"></script>

Now to add the structure for the height converter using the <h1> tag we will add the heading for our height converter and then using the input type with text we will create the input box for our height converter. Now using the input tag with the type submit we will create the submit button for the height converter.

Create Portfolio Website Using HTML and CSS (Source Code)

<div id="container">
<h1>Height Converter</h1>
Feet
<input type="text" id="feet" /> <br />
Inches
<input type="text" id="inches" /> <br />
<input type="submit" id="submit" value="Convert to cm" /> <br /><br />
<div id="result"></div>
</div>

There Is All The Html Code For The Height Converter. Now, You Can See An Output With A Height Converter Html Code Then We Write Css And Javascript For The Height Converter.

100+ HTML,CSS and JavaScript Projects With Source Code ( Beginners to Advanced)

Only Html Code Output:-

Height Converter HTML CSS JavaScript
Height Converter HTML CSS JavaScript

 

Css Code Height Converter:-

 #container {
width: 375px;
height: 425px;
margin-left: 350px;
margin-top: 65px;
background-color: #000;
padding-left: 30px;
color: #fff;
}
#feet {
width: 150px;
height: 25px;
margin-top: 30px;
margin-left: 15px;
}
#inches {
width: 150px;
height: 25px;
margin-top: 30px;
}
#result {
font-size: 35px;
margin-left: 60px;
color: yellow;
}
#submit {
width: 250px;
height: 35px;
margin-left: 20px;
margin-top: 25px;
border-radius: 5px;
border-style: none;
background-color: red;
color: #fff;
font-size: 25px;
}
h1 {
padding-left: 15px;
padding-top: 25px;
}

Step1:The container’s width and height will be changed to 375 pixels and 425 pixels, respectively, using the ID selector (container). In the future, we’ll introduce a 350px margin using the margin-left property. Additionally, we’ll change the background colour to “black” using the background property.

To add styling to our feet and input box, we will now use the id selector. With the margin property, we will add a left margin of 60 pixels and change the font colour to “yellow.” We will set the width and height to 150 pixels and 25 pixels, respectively.

Gym Website Using HTML and CSS (Source Code)

Height Converter Using HTML & JavaScript (Source Code)

Step2:We will now style our submission app and show the outcome. We will make our submit button’s backdrop red using the id selector, and we will centre the text using the text align property. We will give our height converter a boundary radius of 5 pixels by using the border radius property.

#result {
font-size: 35px;
margin-left: 60px;
color: yellow;
}
#submit {
width: 250px;
height: 35px;
margin-left: 20px;
margin-top: 25px;
border-radius: 5px;
border-style: none;
background-color: red;
color: #fff;
font-size: 25px;
}
h1 {
padding-left: 15px;
padding-top: 25px;
}

Only Html And Css Updated Code Output:-

Height Converter HTML CSS JavaScript

 

Javascript Code For Height Converter:-

//BMI = KG / (H/100 * H/100)
document.getElementById("submit").addEventListener("click", heightConverter);
function heightConverter(){
var feet = parseInt(document.getElementById("feet").value *12);
var inches = parseInt(document.getElementById("inches").value);
var cm = (feet + inches) *2.54;
var n = cm.toFixed(0);
document.getElementById("result").innerHTML = n;
}

The HTML element will be first chosen using the page inside of our javascript. getElementById. Using the height converter function, we will build a function for our height converter and add an event listener to receive notifications when the submission button is clicked. We will calculate the number using the feet and inches variables, and then we will include the feet and inches in the cm variable to complete our height conversion.

Ecommerce Website Using HTML, CSS, & JavaScript (Source Code)

Final Output Of Height Converter Using JavaScript

Height Converter Javascript
Height Converter Javascript

 

Height Converter Javascript
Height Converter Javascript

 

Now That We Have Completed Our Javascript Code Section. Here Is Our Updated Output With Html,css And Javascript For Height Converter. Hope You Like The Height Converter Project.

10+ Javascript Project Ideas For Beginners( Project Source Code)

You Can See The Output Video And Project Screenshots. See Our Other Blogs And Gain Knowledge In Front-end Development.

Video Output Of Height Converter:

Codepen Preview Of Height Converter:

Thank You!

ADVERTISEMENT

In This Post, We Learn How To Create A Height Converter Using Simple Html, Css, And Javascript. If We Made A Mistake Or Any Confusion, Please Drop A Comment To Reply Or Help You In Easy Learning.

ADVERTISEMENT

Written By – Code With Random/anki
Code By – Contact Us For Credit

ADVERTISEMENT

What is a Height Converter?

The web calculator height converts foot and inch measurements to centimetres and gives the user’s height in centimetres.

ADVERTISEMENT

What is the formula to convert feet into the centimeter?

To convert feet to cm, multiply the given foot value by 30.48 cm. For example, if 4 ft = 4 x 30.48, we get 121.44 cm.

ADVERTISEMENT



Leave a Reply