Hello Friends Today, through this tutorial, I will tell you How to Create a Height Converter Using HTML CSS and JavaScript?.
Certainly! Here’s a simple Height Converter using HTML, CSS, and JavaScript:
heightconverter.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Height Converter</title> <style> body { font-family: Arial, sans-serif; margin: 0; padding: 0; display: flex; align-items: center; justify-content: center; height: 100vh; background-color: #f4f4f4; } #converter-container { text-align: center; padding: 20px; border: 1px solid #ccc; border-radius: 5px; background-color: #fff; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } label { font-size: 18px; margin-bottom: 10px; } input { padding: 8px; font-size: 16px; } button { padding: 10px; font-size: 16px; cursor: pointer; background-color: #4caf50; color: #fff; border: none; border-radius: 4px; } #result { margin-top: 20px; font-size: 18px; } </style> </head> <body> <div id="converter-container"> <h2>Height Converter Tool</h2> <label for="heightInput">Enter Height (in inches):</label> <input type="number" id="heightInput" placeholder="Enter height in inches"> <button onclick="convertHeight()">Convert</button> <p id="result"></p> <script> function convertHeight() { // Get the value from the input const heightInInches = document.getElementById('heightInput').value; // Check if the input is a valid number if (!isNaN(heightInInches)) { // Convert inches to centimeters (1 inch = 2.54 centimeters) const heightInCentimeters = heightInInches * 2.54; // Display the result document.getElementById('result').innerHTML = `${heightInInches} inches is equal to ${heightInCentimeters.toFixed(2)} centimeters.`; } else { // Display an error message if the input is not a valid number document.getElementById('result').innerHTML = 'Please enter a valid number for height in inches.'; } } </script> </div> </body> </html>
This code creates a simple form with an input field for height in inches and a button to trigger the conversion. The result is displayed below the button. Feel free to customize the styling and layout according to your preferences.