Convert Decimal to Hex Using Javascript with HTML

Hello Friends Today, through this tutorial, I will tell you How to Decimal to Hex Convert Using Javascript with HTML? You can create a simple HTML page with JavaScript to convert a decimal number to its hexadecimal representation.

Here’s an example:


<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Decimal to Hex Converter</title>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;

<h2>Decimal to Hex Converter</h2>

<label for="decimalInput">Enter Decimal Number:</label>
<input type="number" id="decimalInput" oninput="convertToHex()">

<p>Hexadecimal: <span id="hexResult">0</span></p>
function convertToHex() {

// Get the decimal input value
var decimalInput = document.getElementById('decimalInput').value;

// Convert to hexadecimal
var hexResult = Number(decimalInput).toString(16).toUpperCase();

// Update the result in the HTML
document.getElementById('hexResult').innerText = hexResult || '0';


Copy and paste this code into an HTML file and open it in a web browser. Enter a decimal number in the input field, and it will display the corresponding hexadecimal representation. The `convertToHex` function is triggered whenever the input value changes, updating the result dynamically.