How to Create: Speed Converter

Learn how to create a speed converter using HTML and JavaScript.

Speed Converter

Enter a value in any field to convert between speed units:

Create a speed converter

Create an input element that can convert one speed unit to another.

Step 1 - Add HTML:

<p>
  <label>MPH</label>
  <input id="inputMPH" type="number" placeholder="MPH"
  oninput="speedConverter(this.value)"
  onchange="speedConverter(this.value)"
</p>
<p>KPH: <span id="outputKPH"></span></p>

Step 2 - Add JavaScript:

Miles per hour to kilometers per hour:

/* Convert value from mph to kph when input field receives input */
function speedConverter(valNum) {
  valNum = parseFloat(valNum);
  document.getElementById("outputKPH").innerHTML = valNum * 1.609344;
}

Try it yourself

Convert MPH to other units

The following table shows how to convert MPH to other speed units:

Description Formula Example
Convert MPH to KPH KPH = MPH * 1.609344 Try It
Convert MPH to knots knots = MPH / 1.150779 Try It
Convert MPH to Mach Mach = MPH / 761.207 Try It

Convert KPH to other units

The following table shows how to convert KPH to other speed units:

Description Formula Example
Convert KPH to MPH MPH = KPH / 1.609344 Try It
Convert KPH to knots knots = KPH / 1.852 Try It
Convert KPH to Mach Mach = KPH / 1225.044 Try It

Convert knots to other units

The following table shows how to convert knots to other speed units:

Description Formula Example
Convert knots to MPH MPH = knots * 1.150779 Try It
Convert knots to KPH KPH = knots * 1.852 Try It
Convert knots to Mach Mach = knots / 661.4708 Try It

Convert Mach to other units

The following table shows how to convert Mach number to other speed units:

Description Formula Example
Convert Mach to MPH MPH = Mach * 761.207 Try It
Convert Mach to KPH KPH=Mach*1225.044 Try It
Convert Mach to Knots knots=Mach*661.4708 Try It