How to Convert IP to Binary Using JavaScript With HTML With Example?

Hello Friends Today, through this tutorial, I will tell you How to IP to Binary Convert Using JavaScript Without Submit Button with HTML? You can create a simple IP to Binary Converter using JavaScript with HTML without a submit button. Below is an example:


<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IP to Binary Converter</title>
body {
font-family: Arial, sans-serif;
margin: 20px;
label {
display: block;
margin-bottom: 8px;
input {
width: 100%;
padding: 8px;
margin-bottom: 16px;
box-sizing: border-box;
<h2>IP to Binary Converter</h2>
<label for="ipAddress">Enter IP Address:</label>
<input type="text" id="ipAddress" placeholder="Enter IP address" oninput="convertToBinary()">
<h3>Binary Representation:</h3>
<p id="binaryResult"></p>
function convertToBinary() {
// Get the IP address input value
const ipAddress = document.getElementById('ipAddress').value;
// Validate the IP address
if (/^(\d{1,3}\.){3}\d{1,3}$/.test(ipAddress)) {
// Split the IP address into octets
const octets = ipAddress.split('.');
// Convert each octet to binary
const binaryArray = => {
const binary = parseInt(octet, 10).toString(2).padStart(8, '0');
return binary;
// Display the binary result
document.getElementById('binaryResult').innerHTML = binaryArray.join('.');
} else {
// Display an error message for invalid input
document.getElementById('binaryResult').innerHTML = 'Invalid IP address';

This HTML file includes an input field for entering an IP address. As the user types, the `convertToBinary` function is triggered, which converts the IP address to its binary representation and updates the result on the page. The input is validated to ensure it matches the format of a typical IP address. If the input is invalid, an error message is displayed.


IP to Binary Converter

IP to Binary Converter

Binary Representation: