How to create: Temperature converter
- Previous page Convert weight
- Next page Convert length
Learn how to use HTML and JavaScript to create a temperature converter.
Temperature converter
Type a value in any field to convert between temperature units:
Create a temperature converter
Create an input element that can convert one temperature unit to another.
Step 1 - Add HTML:
<p> <label>Fahrenheit</label> <input id="inputFahrenheit" type="number" placeholder="Fahrenheit" oninput="temperatureConverter(this.value)" onchange="temperatureConverter(this.value)" </p> <p>Celsius: <span id="outputCelsius"></span></p>
Step 2 - Add JavaScript:
Fahrenheit to Celsius conversion:
/* When the input field receives input, convert the value from Fahrenheit to Celsius */ function temperatureConverter(valNum) { valNum = parseFloat(valNum); document.getElementById("outputCelsius").innerHTML = (valNum-32) / 1.8; }
Convert Fahrenheit to other units
The table below shows how to convert Fahrenheit to other temperature units:
Description | Formula | Example |
---|---|---|
Convert Fahrenheit to Celsius | ℃=(℉-32)/1.8 | Try it |
Convert Fahrenheit to Kelvin | K=((℉-32)/1.8)+273.15 | Try it |
Convert Celsius to other units
The table below shows how to convert Celsius to other temperature units:
Description | Formula | Example |
---|---|---|
Convert Celsius to Fahrenheit | ℉=(℃*1.8)+32 | Try it |
Convert Celsius to Kelvin | K=℃+273.15 | Try it |
Convert Kelvin to other units
The table below shows how to convert Kelvin to other temperature units:
Description | Formula | Example |
---|---|---|
Convert Kelvin to Fahrenheit | ℉=((K-273.15)*1.8)+32 | Try it |
Convert Kelvin to Celsius | ℃=K-273.15 | Try it |
- Previous page Convert weight
- Next page Convert length