• More Courses
  • MCQs
  • Blog Download
  • Tools
  • Contact

    HTML and JavaScript Code to find the GCD (Greatest Common Division) of two numbers.

    Posted on 2021-08-02

    According to Wikipedia - In mathematics, the greatest common divisor (gcd) of two or more integers, when at least one of them is not zero, is the largest positive integer that divides the numbers without a remainder. For example, the GCD of 8 and 12 is 4.

    Here in this page I have shared HTML and Javascript program to find the greatest common division of two number. 


    <!DOCTYPE html>
        <title> GCD Using Euclidean Algorithm </title>
                background-color: lime; 
                margin: auto;
                width: 40%;
                border: 3px solid green;
                padding: 10px;
                margin-top: 100px;
                background-color: rgb(230, 146, 230);
                padding: 2px;
                text-align: center;
                margin-bottom: 15px;
                font-size: 40px;
                margin-left: 50px;
                background-color: #2d0af5; /* Green */
                border: none;
                border-radius: 10px;
                color: white;
                padding: 15px 32px;
                text-align: center;
                font-size: 16px;
                margin: 4px 2px;
                cursor: pointer;
            input[type=number] {
                width: 100%;
                box-sizing: border-box;
                border: 2px solid #ccc;
                border-radius: 4px;
                font-size: 16px;
                background-color: white;
                padding: 10px;
    <div class="main">
        <div class="head">
            <h2> GCD (Find Greatest Common Division) </h2>
        <div style="text-align: center">
        <input type="number" placeholder="Enter R1" id="r1" required> <br> <br>
        <input type="number" placeholder="Enter R2" id="r2" required> <br> <br>
        <button class="btn" type="button" onclick="getInputValue();">Get Value</button>
        <div class="result">
            GCD = <span id="gcd" style="color: #ff0000"></span>
    <div style="background-color: #ccc; padding: 2px; bottom: 0; position: fixed; width: 100%;">
            <p> Created By Raj </p>
        function gcd(a, b) {
        var R;
        while ((a % b) > 0)  {
            R = a % b;
            a = b;
            b = R;
        return b;
        function getInputValue(){
            var r1 = document.getElementById("r1").value;
            var r2 = document.getElementById("r2").value;
            document.getElementById("gcd").innerHTML = gcd(r1, r2);